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
 General SQL Server Forums
 New to SQL Server Programming
 duplicate tables not data

Author  Topic 

noyellatmonkeys
Starting Member

15 Posts

Posted - 2009-11-22 : 23:31:49
hello,

I need to duplicate the tables from one database to another. I do not need the data.

i use sql server management studio express. I used the import/export wizard and copied the tables over (data and all, i figured i would just delete the data afterwards). But although the tables were there, it was missing the column attributes like that id is identity and to auto increment or the default values i have for some of the columns. Any suggestions how i can get the tables over with the column attributes? whether the data copies over is irrevalent.

Thank you!

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2009-11-23 : 02:12:45
Generate script for objects (Tables,Views,Functions,Sps and Schema) from your source database and execute it in target database.
Go to Top of Page

kbhere
Yak Posting Veteran

58 Posts

Posted - 2009-11-23 : 06:26:29
SELECT INTO destinationdatabase.schemaname.tablename FROM sourcedatabase.schemaname.tablename

This is the general syntax for copying table from one database to another.. but this will copy the table along with the data..

Since you have enquired for copying tables i have posted this..


Wishes,




Balaji.K
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-23 : 07:10:06
quote:
Originally posted by kbhere

SELECT INTO destinationdatabase.schemaname.tablename FROM sourcedatabase.schemaname.tablename

This is the general syntax for copying table from one database to another.. but this will copy the table along with the data..

Since you have enquired for copying tables i have posted this..


Wishes,




Balaji.K



It will not copy the indices. Better way is generating sql script and running it on the target database

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-11-23 : 08:07:34
I'd generate the scripts through SSMS and not a SELECT * INTO statement
Go to Top of Page

noyellatmonkeys
Starting Member

15 Posts

Posted - 2009-11-23 : 12:19:52
Thank you everybody on your advice and time.
Go to Top of Page
   

- Advertisement -