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
I wrote an open source command line utility named SchemaZen that does this. It's much faster than scripting from management studio and it's output is more version control friendly. It supports scripting both schema and data.
To generate scripts run:
schemazen.exe script --server localhost --database db --scriptDir c:\somedir
Then to recreate the database from scripts run:
schemazen.exe create --server localhost --database db --scriptDir c:\somedir
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.
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.
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)
-- Sleep: 5
-- Sleep after creating database to allow file system to create db files
CREATE DATABASE [$Database$]
GO
EXEC sp_dbcmptlevel [$Database$], $CompatabilityLevel$
GO
USE [$Database$]
GO
IF '1'!='$IntegratedSecurity$'
BEGIN
CREATE LOGIN [$Login$] WITH PASSWORD=N'$Password$', DEFAULT_DATABASE=[$Database$]
CREATE USER [$User$] FOR LOGIN [$Login$]
EXEC sp_addrolemember N'db_owner', N'$User$'
END
GO
From Management Studio Right-click on your database. Tasks -> Generate Scripts.
That should do it.
I recommend looking at RedGate SQL packager. It is not free, but has been useful enough to be worth the price.