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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 copy table structure

Author  Topic 

bootsy
Starting Member

7 Posts

Posted - 2008-03-05 : 13:17:13
I need to duplicate the structure of a table. I don't need the data. But I need to have the exact same field names and data types. How do I duplicate a table?

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2008-03-05 : 13:31:53
INSERT INTO (...)
SELECT ....
FROM SourceTable
WHERE 1=0




Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

bootsy
Starting Member

7 Posts

Posted - 2008-03-05 : 13:44:58
Thank you but it didn't work. I tried this:

INSERT INTO (dbo.May_2006_Parse)
SELECT ....
FROM dbo.April_2005_Parse
WHERE 1=0


This is the error I get;

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '('.
Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'FROM'.


I'm extremely new to SQL. Can you bare with me please?
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-03-05 : 14:16:13
select top 0 * into dbo.May_2006_Parse from dbo.April_2005_Parse

But it would be better to just script the table create statement, that way you get indexes, constraints, etc.





"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

bootsy
Starting Member

7 Posts

Posted - 2008-03-05 : 15:00:28
Thanks jhocutt. It works beautifully! Thank you everyone for all your help.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-06 : 08:15:53
quote:
Originally posted by bootsy

Thank you but it didn't work. I tried this:

INSERT INTO (dbo.May_2006_Parse)
SELECT ....
FROM dbo.April_2005_Parse
WHERE 1=0


This is the error I get;

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '('.
Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'FROM'.


I'm extremely new to SQL. Can you bare with me please?


You should have tried

select * into dbo.May_2006_Parse from dbo.April_2005_Parse
where 1=0


Madhivanan

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

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-03-06 : 08:52:57
Do you really need to put each month in it's own table? Why are you doing this? All of your data that is of the same type should be in one single table, with a a simple "month" column to indicate which month each row belongs to.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -