SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Create And Execute Table Script (SQL Server 2000)

By Robert Marda, 2002/10/15

Total article views: 446 | Views in the last 30 days: 104

This SP will only work on SQL Server 2000 and can be placed in your master database. sp_CreateAndExecTableScript is designed to script one table and create an identical table. I designed it to use with DTS packages so that I can create an identical table with a different name, pump data into the table and then rename the new table to the name of the original table. Here is a sample call for the stored procedure to script everything related to a table: exec sp_CreateAndExecTableScript @Exec = 1, @DisplayScript = 1, @TableName = 'authors', @TableNameExt = '_New' This will create a duplicate table in the pubs database for the table authors. If you set @NoIndexes = 1 and @NoPK = 1 then you will only get the table and default values. If you set @PKOnly = 1 then you will only get the script for the primary key. If you set @NoTable = 1 then you will only get the script for the primary key and/or the indexes. If you want to see the script without executing it then make sure you set @Exec = 0 and @DisplayScript = 1. I do not guarantee it will script all tables correctly, however my testing shows it will script most tables and indexes correctly. If you find something about a table or index it doesn't script properly please let me know and I will see about fixing it.

By Robert Marda, 2002/10/15

Total article views: 446 | Views in the last 30 days: 104
Your response
 
 
Related tags

T-SQL Aids    
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com