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.
| Author |
Topic |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-09-07 : 05:48:51
|
| is there a simple sql syntax to copy a table compete with data??? |
|
|
HCLollo
Starting Member
49 Posts |
Posted - 2005-09-07 : 05:57:29
|
esthera, you mean something like the following?INSERT INTO NewTableSELECT *FROM OldTable HCL"If it works fine, then it doesn't have enough features" |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2005-09-07 : 06:03:00
|
| yes -- will that work if the newtable wasn't yet created or do I have to create it first?Will it keep primary keys and identities and defaults? |
 |
|
|
asarak
Starting Member
36 Posts |
Posted - 2005-09-07 : 06:14:40
|
| select * into newtable from oldtable |
 |
|
|
HCLollo
Starting Member
49 Posts |
Posted - 2005-09-07 : 06:31:48
|
| Esthera, you should create the table before the INSERT.HCL"If it works fine, then it doesn't have enough features" |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-07 : 07:01:37
|
| "Will it keep primary keys and identities and defaults?"Nope ...SELECT * INTO TableToBeCreated FROM MyExistingTablewill create a new table with appropriate datatype for each column.Otherwise you need to doCREATE TABLE MyNewTable(...)INSERT INTO MyNewTableSELECT *FROM MyOldTableSQL Server has a number of ways that you can use to get a "script" of the existing table, and then you can just "find&replace" to make a new script. This can include all indexes, PKs, defaults, IDENTITY, extended properties and so onKristen |
 |
|
|
|
|
|