Search code examples
c#ado.net.net-2.0sql-server-2000

ADO.NET command to script database creation


Is there a SELECT command I can execute in ADO.NET to retrieve a script that will rebuild my database from scratch with empty tables? I'd like to be able to script the creation of the database itself, along with all the tables, views, and stored procedures and any relationships that exist between the tables. Also primary key and identity specifications.

I am using SQL Server 2000 and C# (.NET Framework 2.0).


Solution

  • There is no such SELECT command but you can use SQL Server Management Studio to generate such a script for you.

    Context menu for a database in Object Explorer has Script Database as option that should do the trick for you. Then you could execute the resulting script from your program using standard SqlCommand objects.