Script entire database SQL-Server
Is there a way I can get a scripting of all tables, procs, and other objects from a database? I know there’s an option to script the database but it only gave me some sort of top level script, certainly not a script to create all tables, procs, udfs, .etc.


rajesh on Mar 05, 2013
We ended up using a combination of SSMS script generation to extract schema and data, and then use our own database tool which allows keyword parsing and token based replacement in scripts. It also ensures scripts are only applied once.
Why?
Example script (edited for brevity)
cheeseballlumpy82 on Mar 05, 2013
From Management Studio
Right-click on your database.
Tasks -> Generate Scripts.
That should do it.
harry on Mar 05, 2013
I wrote a utility for this task, SMOscript.
Script generation is performed by the SMO library, and supports the new object types in SQL 2005 and 2008.
xequnsruuh on Mar 05, 2013
If you need to do it programmatically, you can use the SQL DMO library (OLE) against SQL Server 2000, but more likely you may wish to use the SQL SMO library (native .NET libraries) against SQL Server 2005 and later.
Both these libraries are integral to the SQL Server administrative tools install.
This is in the case that generating the full database script from SQL Server Management Studio is insufficient.
harry on Mar 05, 2013
I recommend looking at RedGate SQL packager. It is not free, but has been useful enough to be worth the price.