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
 Create new table from existing table

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 0
INTO
History.HistoryLog2009
FROM
History.HistoryLog2008
Go to Top of Page

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=0


kiruthika
http://www.ictned.eu
Go to Top of Page

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?
Go to Top of Page

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
Go to Top of Page

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

Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-07-02 : 09:23:00
Did you see what I posted?
Go to Top of Page

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 TO

Jim
Go to Top of Page

ninedoors
Starting Member

4 Posts

Posted - 2008-07-02 : 09:35:17
Thanks sodeep and Jim. Worked perfectly.

Nick
Go to Top of Page
   

- Advertisement -