Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved in your SSC briefcase from the favorites tab.
Download now (direct download link)

Create And Execute Table Script (SQL Server 2000)

By Robert Marda,

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.

Total article views: 1337 | Views in the last 30 days: 3
 
Related Articles
FORUM

script to create indexes existing in a database

script to create indexes existing in a database

SCRIPT

Scripting CREATE INDEX Statements Automatically From Your Tables

Stored proc for scripting out full CREATE INDEX statements from your table indexes with all filegrou...

SCRIPT

Script to Compress Tables and Indexes

This script creates scripts to compress all tables and indexes in a database.

SCRIPT

Script all Indexes

Generate scripts for all indexes in a database

FORUM

INDEX NAME, TAble Name, Index Script required.

INDEX NAME, TAble Name, Index Script.

Tags
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones