Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a copy of a table within SQL Server Enterprise Manager?

Tags:

sql

sql-server

This is one of those "I probably should know this, but I don't" questions. How do I make a copy of a table in Enterprise Manager? Not export the data into a different database, just make a copy of the table within the same database. At this point, I don't care whether the data comes with or not, but the table definition should definitely be duplicated.

If I do Ctrl+C on a selected table and paste the results into a text editor, it gives me a Create Table statement that looks promising, but I can't for the life of me find any place to run that statement.

Edit: note that I'm asking about SQL Server Enterprise Manager. This is NOT the same thing as "SQL Server Management Studio". There's no "New Query" button, neither in the top left corner nor anywhere else. In fact, the word 'query' does not occur anywhere in EM except on the Tools menu, and there it's a link to Query Analyzer.

like image 334
Martha Avatar asked Jul 03 '09 17:07

Martha


3 Answers

Copy a table with all content (without keys and constraints)

select * into tablecopy from table 

Copy a table without content (without keys and constraints)

select top 0 * into tablecopy from table 

There's a way to copy it with all constraints, in the right click menu (of the table) then all tasks then script as then create to then new query editor window (or a file). You will have to modify the generated script so the constraints and keys are named differently though, and then do an

insert into tablecopy select * from table

to populate it.

EDIT: If what you are actually asking is a place to run SQL in the Enterprise Manager, try either the Query Analyzer or the Management Studio.

like image 122
Vinko Vrsalovic Avatar answered Nov 07 '22 13:11

Vinko Vrsalovic


SELECT * INTO MyNewTable FROM MyOldTable

The new table will be created without primary keys, foregin keys nor anything else

like image 21
Jhonny D. Cano -Leftware- Avatar answered Nov 07 '22 15:11

Jhonny D. Cano -Leftware-


If you're talking 2000 enterprise manager: Tools -> Query analyzer Will give you a place to execute the query.

like image 5
feihtthief Avatar answered Nov 07 '22 15:11

feihtthief