Wednesday, March 7, 2012

Copy a Table

In MS Access, if I want to copy a table, I can just highlight it, hit ctrl-c and ctrl-v, and VOILA! I now have a "copy of MyTable" pasted, with all data duplicated.

Um. How do I do the same thing in SQL Server 2005? Can this be done with Server Management Studio? I don't necessarily want to copy relationships to other tables, I just want a stand-alone copy of the table, with a new name, inside the same database.

(EDIT): I just noticed I can achieve this outcome with:

SELECT * INTO TestIT FROM TestCases

...and while that is simple enough to get the job done, I kinda still wonder if there is a GUI-oriented means to accomplish this (like Access does), without writing bits of SQL as above.

the closest function of SQL Mgmt. Studio to what you are describing is the import/export wizard (right-click on a a database in object explorer and select tasks/[import or export]. But I dont think it will allow you to specify the same source and destination (you may want "play" with the wizard a bit to ensure you cannot get it to work for you). Outside of that...NO. A related features is that of scripting data, so you could right-click a table and select Script Table As/"Generate Data", I believe SQL tools will have this feature in the future, but I would think other third-party tools already do this, not sure though if this can be done via the SMO model yet or not...

No comments:

Post a Comment