Results 1 to 5 of 5

Thread: [RESOLVED] Duplicate table in mssql server

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Resolved [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.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    Lively Member
    Join Date
    Jun 2008
    Location
    Bayang Magiliw, Perlas Ng Silangan
    Posts
    100

    Re: Duplicate table in mssql server

    or you can run a query similar to this:

    Code:
    SELECT *
    INTO Persons_Backup
    FROM Persons

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: [RESOLVED] Duplicate table in mssql server

    Thanks. That did it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width