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
 Transact-SQL (2000)
 Copy table structure for DB1 to DB2

Author  Topic 

Everald Smith
Starting Member

2 Posts

Posted - 2005-03-07 : 05:39:13
Pleade help. What is best way of copying tables structure (not data) from one Database to a second Database on the same instance of SQL 2000. I need to copy some tables not all.

nr
SQLTeam MVY

12543 Posts

Posted - 2005-03-07 : 05:47:35
Easiest to script them and run the script.
If the structure without indexes then you could (in the dest database)

select * into mytbl from db1..mytbl where 1=0

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

henrikop
Constraint Violating Yak Guru

280 Posts

Posted - 2005-03-07 : 07:01:50
"The Best Way" depends on what you want. Do you want to do it one time? Of scheduled?

If it's just to "fill" another database with the structure so you can test something, I'd say use DTS.

If you right-click on any the database in de Enterprise manager, choose All Tasks and choose Export. Select source DB and destination DB and choose "Copy Objects and Data..." Than make sure that you don't select COPY DATA flag and than you can select anything you want. It's very powerful. I like the SAVE DTS on SQL Server in the end so you can see what DTS does and that you can use it another time (or schedule it!! for testing this is SUPER).


Henri
~~~~
Anyone who can walk to the welfare office can walk to work.
- Al Capone
Go to Top of Page

Everald Smith
Starting Member

2 Posts

Posted - 2005-03-09 : 10:14:12
Thanks! I use the DTS
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-03-10 : 00:45:06
Does that do Foreign Keys and Additional Indexes and stuff?

Kristen
Go to Top of Page

henrikop
Constraint Violating Yak Guru

280 Posts

Posted - 2005-03-10 : 02:39:45
No, but you could script these in DB1 (as Nigel pointed out). Save the DTS package and add a sql task. Since there will be no data in DB2, this shouldn't be a problem. And... learning is a step by step process, one step at a time. Reading the post, I gave an answer which might be at help for a novice ms sql programmer.

But you are right, in the learning process I am some steps behind you

Henri
~~~~
Anyone who can walk to the welfare office can walk to work.
- Al Capone
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-03-10 : 13:21:36
Hey, don't fret, I didn't know and actually I was hoping you would say "Yup" so I could say "Darn it! I wish I'd known that all these years!"

Kristen
Go to Top of Page
   

- Advertisement -