Discussion Locked

How to Script a MS SQL Server Table

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Besides using MS SQL Server Enterprise Manager, does anyone have a method of scripting a Microsoft SQL Server table and it's related indexes into TSQL code? I want to create a SQL Server job to DROP & CREATE a table, but instead of 'hard coding' the TSQL code in a jobstep to create my table, I would prefer to generate the TSQL CREATE command immediately prior to the DROP step, and then run that TSQL script to recreate my table after doing the DROP.

5 replies

by geoff.walter

I was looking for a method to generate the t/sql CREATE code based on the already-existing table(s).

by mattohare

Using a COM related language such as VB or VC++, you can use the SQLDMO object to script objects. I use this as part of my documentation process.

Most of the objects in SQLDMO (tables, views, stored procedures, indexes, constraints, etc.) use sqldmo.

The method is "Script" and it even includes the GO statements and SET statements to make it work. If you like, I'll be happy to share examples from my source code.

This discussion is closed to new replies.