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
 creating a duplicate table

Author  Topic 

svicky9
Posting Yak Master

232 Posts

Posted - 2005-08-04 : 15:42:29
Hi i want to create a duplicate table in t-sql with the same column fields in but no data in it
Can anyone help me
I remember in Oracle u can do it like


create table duplicate as select * from original_table where 1 = 2


with the false condition we can create a table with the same columns

I tried the same with t-sql but i cannot do it.
Can anyone tell me how to do it...

Thanks
Vicky

Vicky

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-04 : 16:15:16
SELECT * INTO NewTable FROM OldTable WHERE 1=0

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

svicky9
Posting Yak Master

232 Posts

Posted - 2005-08-04 : 16:52:39
thank you


Vicky
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-05 : 03:12:57
>>SELECT * INTO NewTable FROM OldTable WHERE 1=0

It should be noted that Newtable wont have any indexes
The best way is Generate table script of Oldtable and rename the table name and run it

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2005-08-05 : 04:38:49
Like this?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53007



Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-05 : 08:51:42
quote:
Originally posted by madhivanan
The best way is Generate table script of Oldtable and rename the table name and run it



What if the table has a billion rows?

The answer is always...it depends...and since we don't know what they're trying to accomplish, that goes double.

MOO



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-05 : 08:56:55
>>What if the table has a billion rows?

I dont think number of rows matters when generating script of a table
Do you think there is performance issue?

Madhivanan

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

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-05 : 09:24:06
[d'oh]
damn hangover...

Nope...there isn't

I forgot that they didn't want the data.....

[/d'oh]




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-05 : 09:26:13
Not fully returned from Cruise

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2005-08-05 : 09:40:01
"I forgot that they didn't want the data....."

Blimey! Loads of grey cells must have gone bye-bye for you to forget overnight that you typed

SELECT * INTO NewTable FROM OldTable WHERE 1=0



Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-05 : 09:55:24
Well duh...that was like a whole 20 hours ago.....

damn hangover....



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -