Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 copy table w/o data and with new name

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-01-23 : 23:18:26
Hi people,

How can I copy a table that already exists in my database, but without copying over the tables data.

I want all the tables properties including indexes, Primary Key's, defaults etc.

I tried DTS but it seems to transfer the tables data also, and it doesn't copy over the PK and column defualts etc.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-01-23 : 23:20:48
Just script out the object using the Generate SQL Script wizard. Right click on the database, all tasks, generate sql script. Make sure to go to the last tab and select the options that you want.

Tara Kizer
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-23 : 23:21:16
use Enterprise Manager to script out the table and run the script in your destination database


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-23 : 23:24:09



KH

Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2007-01-25 : 07:02:01
yeah that is what I did, I was hoping for a built-in function I could use like: copy_table_and_rename MyTable.

thanks!
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-01-25 : 07:26:25
"I was hoping for a built-in function"

In Enterprise Manager use the Table Design tool to:

a) Open existing table
b) Create a new table

Highlight the rows in the Old table's properties window, and copy & paste to the New table.

Kristen
Go to Top of Page
   

- Advertisement -