views:

1003

answers:

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.

+2  A: 

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.

Blorgbeard
A: 

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