Groups | Blog | Home
all groups > sql server programming > august 2004 >

sql server programming : Copy Table Structure to Same Database


clintonG
8/13/2004 9:48:32 PM
I have created a table with many columns that needs to be duplicated
within the same database where the duplicate table can then be modified.

The context menu in the Enterprise Manager enables a copy selection
but then there is no paste. Using Query Analyzer I tried the following...

SELECT *
INSERT TargetTable
FROM SourceTable

.... producing results that state the table has been created but the new
table can not be seen when returning to the Enterprise Manager.

Can somebody explain how to get this done?

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET csgallagher@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


Dan Guzman
8/13/2004 10:51:52 PM
I assume there is a typo in your post and you used SELECT ... INTO:

SELECT *
INTO TargetTable
FROM SourceTable

You might try refreshing the table list in Enterprise Manager.

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

clintonG
8/13/2004 11:34:57 PM
I didn't know it could do that %-)

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET csgallagher@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/



[quoted text, click to view]

clintonG
8/14/2004 10:10:20 AM
I used the INSERT keyword and the table structure was copied
into a new instance. The problem I was having is that Enterprise
Manager would not show me the new table even though Query
Analyzer response stated it had finsihed the task. I finally had to
close and restart Enterprise Manager which I should have tried
before posting.


Thanks Dan and Roji.


--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET csgallagher@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/



[quoted text, click to view]

Roji. P. Thomas
8/14/2004 12:10:22 PM

[quoted text, click to view]

This statement will give you a syntax Error only.
To copy the structure and data use


SELECT *
INTO TargetTable
FROM SourceTable

The table will be created as current user as the owner.
If you want to create it int he dbo's context use

SELECT *
INTO dbo.TargetTable
FROM SourceTable

If you just want the structure and not data add a condition like

SELECT *
INTO TargetTable
FROM SourceTable
WHERE 1=0

--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com


[quoted text, click to view]

Aaron [SQL Server MVP]
8/14/2004 12:27:20 PM
[quoted text, click to view]

Usually all that is needed is to right-click the tables node and hit
refresh.

You can also use Query Analyzer's object browser (F8) instead of having to
keep two GUIs open.

--
http://www.aspfaq.com/
(Reverse address to reply.)

AddThis Social Bookmark Button