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
 copy table properties

Author  Topic 

sunny_pa
Starting Member

2 Posts

Posted - 2010-12-02 : 04:37:15
sir,

i have two databases named db1 and db2. T1 is table in db1 and have certain properties like foriegnkey etc. i wanna creat new table T2 in db2 with same properties that of T1. what query should i use.

regards

sunny gupta

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-02 : 04:46:15
Easiest to sript the table definition (using management studio), change the table name and run the script.

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

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-12-02 : 04:53:31
or else go through the link
http://www.databasejournal.com/features/mssql/article.php/3507171/Transferring-Data-from-One-Table-to-Another.htm

With Regards
Kashyap M
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-02 : 05:13:27
quote:
Originally posted by kashyap_sql

or else go through the link
http://www.databasejournal.com/features/mssql/article.php/3507171/Transferring-Data-from-One-Table-to-Another.htm

With Regards
Kashyap M



Think that only covers creating the structure and copying data.

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

sunny_pa
Starting Member

2 Posts

Posted - 2010-12-02 : 06:15:11
but sir, what if both tables dont have same structure and we wanna copy T1 as it is to T2
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-02 : 06:18:42
If you copy T1 as it is to T2 then they will have the same structure (by definition).
If you want the structures to be different then change the creation script before applying it.

Just to clarify from your OP - T2 doesn't exist and you want to create it with the same properties as T1.

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

- Advertisement -