|
-
May 22nd, 2011, 09:58 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Duplicate table in mssql server
Is there an easy way to duplicate a table (schema & data) using MSSQL Server Management Studio (Express)? I want to create a duplicate table before I run a data update. If there's a problem, I want to be able to easily rollback to the previous version.
-
May 23rd, 2011, 01:37 AM
#2
Re: Duplicate table in mssql server
You can get the script of a table by right clicking on it and selecting Script Table As -> CREATE TO -> New Query Editor Window.
But be aware that you cannot have 2 tables having the same names, you must have a different name for the other table. And when you are saving then you can just insert into that table the record being updated/inserted. That is called Audit Logging.
-
May 23rd, 2011, 02:57 PM
#3
Lively Member
Re: Duplicate table in mssql server
or you can run a query similar to this:
Code:
SELECT *
INTO Persons_Backup
FROM Persons
-
May 23rd, 2011, 03:07 PM
#4
Re: Duplicate table in mssql server
If you want a empty table then
SELECT * INTO Person_Emprty from Person WHERE 1 = 2
That will duplicate the fields and their sizing, it will not rebuild index, constraints, PKs or FKs
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
May 23rd, 2011, 09:04 PM
#5
Thread Starter
Frenzied Member
Re: [RESOLVED] Duplicate table in mssql server
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|