Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Copy the structure of a Table with T-SQL

Status
Not open for further replies.

sgueper

Programmer
May 2, 2002
18
ES
I would like to copy a table (the structure, the indexes) and the relationship with another table in the database.

I will send the query from VB.

Thank you

Silvi

 
Hi

Right click on the database, choose 'Generate SQL Script',
select the table you want, On the options tab choose 'CREATE', 'script indexes', 'primary keys and foreign keys'), select "Preview" and then copy and paste into Query Analyser or save the script as a file.

This will generate the table structure with the indexes but without having the data, just remember to change the table name in the script.

You can also use DTS but select objects which is the 3rd option and don't choose "copy data", change the default options to the PK, indexes, Fk etc and objects to your table, then save as package and then edit the table name again.

For VB you can either use the CREATE script or use VB to execute the DTS package.

Hope this helps

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top