views:

62

answers:

3

anyone know of such stored procs to generate scripts for tables/indexex/views/sp's etc.

A: 

Views and SPs are relatively easy since the code is in the syscomments/INFORMATION_SCHEMA.ROUTINES.

I've created one for tables, but it's not particularly complete - and in fact, it only actually generates the appropriate CREATE TABLE statement for a completely different platform - Teradata, so it turns the PRIMARY KEY into a UNIQUE PRIMARY INDEX (Teradata allows both a PRIMARY KEY and a PRIMARY INDEX, but does not allow the PRIMARY KEY - or any index - to have the same columns as any other index).

I'm not sure there are any standard ones out there, but it would just be a matter of all the little things - getting all the extended properties on columns tables and indexes, etc.

Cade Roux
A: 

I don't know of any stored procs for this but Microsoft has the SQL Server Database Publishing Wizard to generate scripts (structure and data).

Austin Salonen
+1  A: 

The GUI (SQL Server Management Studio) is just a thin shell around the SMO. All the scripting power is inside the SMO. Use the Scripter class. Have a look at this basic intro to SMO scripting: SQL Server: SMO Scripting Basics.

Remus Rusanu
Sweet. Never saw that before.
David Lively