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 |
|
ninedoors
Starting Member
4 Posts |
Posted - 2008-07-02 : 07:49:55
|
| Hi,I would like to create a new table from an existing table but only the structure of that table. So no data from the existing table. The table name of the existing table is History.HistoryLog2008 and the new table will be History.HistoryLog2009. I am using Microsoft SQL Server Management Studio.Thanks for an help.Nick |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-02 : 08:20:56
|
| SELECT top 0INTOHistory.HistoryLog2009FROMHistory.HistoryLog2008 |
 |
|
|
kiruthika
Yak Posting Veteran
67 Posts |
Posted - 2008-07-02 : 08:26:00
|
quote: Originally posted by ninedoors Hi,I would like to create a new table from an existing table but only the structure of that table. So no data from the existing table. The table name of the existing table is History.HistoryLog2008 and the new table will be History.HistoryLog2009. I am using Microsoft SQL Server Management Studio.Thanks for an help.Nick
select * into History.HistoryLog2009 from History.HistoryLog2008 where 1=0kiruthikahttp://www.ictned.eu |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-07-02 : 08:27:36
|
quote: Originally posted by ninedoors Hi,I would like to create a new table from an existing table but only the structure of that table. So no data from the existing table. The table name of the existing table is History.HistoryLog2008 and the new table will be History.HistoryLog2009. I am using Microsoft SQL Server Management Studio.Thanks for an help.Nick
Why don't you script so you won't miss index? |
 |
|
|
ninedoors
Starting Member
4 Posts |
Posted - 2008-07-02 : 08:31:02
|
| Thanks guys I will try these solutions and let you know if they work.Nick |
 |
|
|
ninedoors
Starting Member
4 Posts |
Posted - 2008-07-02 : 09:08:23
|
| The queries are not working as I expected. Maybe I didn't explain myself properly. I would like to attach a screenshot of my program so I can show you the layout? Thanks for the help.Nick |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-07-02 : 09:23:00
|
| Did you see what I posted? |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-07-02 : 09:28:33
|
| Nick,All of the answers would give you what you asked for, sodeep's will give you an exact copy of the table and all it's indexes, constraints, etc. In SSMS, right-click on the table and choose SCRIPT TABLE AS --> CREATE TOJim |
 |
|
|
ninedoors
Starting Member
4 Posts |
Posted - 2008-07-02 : 09:35:17
|
| Thanks sodeep and Jim. Worked perfectly. Nick |
 |
|
|
|
|
|