March 24, 2010 at 1:38 am
Hi
How to script all the tables,Views,index,triggers and Sps in a database without using Generate script wizard. i need script which means that if the script is run then i can take the O/P and run in my local server. I dont want datas thats y i am asking for this.I dont want to use Wizard any other way is there. I am just trying possible way
Thanks
Parthi
Thanks
Parthi
March 24, 2010 at 2:55 am
Are you looking for something like this?
SELECTOBJ.type_desc, OBJ.name, SM.DEfinition
FROMsys.sql_modules SM
JOINsys.objects OBJ
ON OBJ.[object_id] = SM.[object_id]
---------------------------------------------------------------------------------
March 24, 2010 at 4:09 am
hi i got it
DECLARE @Name varchar(100)
DECLARE contact_cursor CURSOR FOR
select Name from sys.sysobjects where xtype in('p','tr','v') order by Xtype
OPEN contact_cursor
FETCH NEXT FROM contact_cursor
INTO @Name
WHILE @@FETCH_STATUS = 0
BEGIN
exec SP_Helptext @Name
FETCH NEXT FROM contact_cursor
INTO @Name
END
CLOSE contact_cursor
DEALLOCATE contact_cursor
GO
If i run the above in my database it will script all the sps,views,tr.
For tables we cant use this so how to get the design structure of the table including index i need to script
Thanks
Parthi
Thanks
Parthi
March 24, 2010 at 5:02 am
You can use the following to avoid cursor
DECLARE @string VARCHAR(MAX)
SET @string = ''
SELECT @string = @string + 'EXEC ( ''sp_helptext ' + name + ' '')' from sys.sysobjects where xtype in('p','tr','v') order by Xtype
EXEC ( @string )
Vaibhav K Tiwari
To walk fast walk alone
To walk far walk together
March 24, 2010 at 5:23 am
Hi
But What about scripting Tables i need to script tables how to do it.
Thanks
Parthi
Thanks
Parthi
March 24, 2010 at 5:59 am
parthi-1705 (3/24/2010)
HiBut What about scripting Tables i need to script tables how to do it.
Thanks
Parthi
As per my knowledge by T-SQL Table script can not be generated :unsure:
Vaibhav K Tiwari
To walk fast walk alone
To walk far walk together
March 24, 2010 at 6:07 am
As per my knowledge by T-SQL Table script can not be generated :unsure:
But how cum it is done tro Generate SQL Script in object explorer
Thanks
Parthi
March 24, 2010 at 6:22 am
oh you can generate the CREATE TABLE script via TSQL; it's just like so many things in SQL Server, the answers are spread out everywhere, and you have to put it together yourself.
take a look at my stored procedure here:
the usage is simple:
exec sp_getDDL tablename
or
exec sp_getDDL 'schemaname.tablename'
I've also contributed an article on it as well:
Get DDL for Any SQL 2005 Table]Get DDL for Any SQL 2005 Table
also, look at my article here:
Exporting your Entire Schema via T-SQL which does exactly what you are asking to do: scripts out every table/function/proc/view in foreign key hierarchy order
Lowell
March 24, 2010 at 7:04 am
Superb thats what i need thanks a lot u have saved my time
Cheers
Parthi
Thanks
Parthi
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply