3

I need to be able to retrieve a CREATE TABLE script to recreate a specific table in a SQL Server (2000) database, programmatically (I'm using C#). Obviously you can do this with Enterprise Manager but I would like to automate it.

I've been playing around with SQLDMO which offers a Backup command, but I'm not sure if this will give a SQL CREATE TABLE script and seems to require the creation of a SQL Service device, and I would prefer to avoid modifying the database.

  • Here is another method http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/generate-sql-script.aspx – Madhivanan Jun 09 '10 at 09:13

2 Answers2

2

Take a look at my solution. It's a sql script which uses the INFORMATION_SCHEMA tables to get the necessary information. It's basic, but might work for you.

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
0

You can use SMO to generate the scripts. For more info see: http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated

Phil Haselden
  • 2,876
  • 3
  • 30
  • 25