Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

when ever we generate script for a sql database from the management studio its generate a script of the database...

how to generate hat script of an online database by sql command....
i found to make it .bak...but how to make sql script..
Posted
Updated 19-Nov-14 22:08pm
v2

SQL Script are stored in syscomments table you can join the syscomments with sys.objects on Object_ID and ID in syscomments. To get the script against each proc or function or views.

SQL
select 
     Object_ID,TEXT 
from 
Sys.Objects Obj 
Join SysComments comm On Obj.Object_id=comm.Id

note, you can have multiple line of Text against an ID if the script is too long.
 
Share this answer
 
Comments
Arkadeep De 20-Nov-14 5:40am    
thanks shweta...but i need all the table data along with proc, function and views
Shweta N Mishra 20-Nov-14 5:44am    
for tables you need to take the backup by a script or by server.
Arkadeep De 20-Nov-14 5:52am    
how?
willington.d 28-Nov-14 1:48am    
SYSComments contains SQL Statements for each view, Trigger, Procedure only. Not for Tables.
sqlcmd does not allow you to do that.
Maybe you can try with Powershell.

For more information, check this link:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/04/use-powershell-to-script-sql-database-objects.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900