Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Duplicating (copying) a table in SQL Server database

Duplicating (copying) a table in SQL Server database

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
2 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I want to copy a table (not rename - the original table should remain as it is) with all the data in it to another table. Is there any way to do it inside a stored procedure in MS SQL Server? Thanks Thomas George

    C 1 Reply Last reply
    0
    • L Lost User

      I want to copy a table (not rename - the original table should remain as it is) with all the data in it to another table. Is there any way to do it inside a stored procedure in MS SQL Server? Thanks Thomas George

      C Offline
      C Offline
      Chanceamatic
      wrote on last edited by
      #2

      Highlight the table and select All Tasks -> Export. This will bring you into DTS. Select the Source and then the Destination (in this case they will be the same). Select Copy Table(s), hit next, select the table you want from the source drop-down and then type in a name for the destination table. You can use Transform here to manipulate the fields, etc. Hit Next, you can run this imediately or save in which you can call this DTS Package from a Job, Stored Procedure, etc. (See BOL about calling DTS packages from an sp.) Another way: Select * into (new_table_name) from (old_table_name) This will create a new table with all the info. (NOTE: This 'transfer' is not logged as a transaction, thus can not be rolled back. I believe you can check FULL RECOVERY on you DB and this will correct this.) Good Luck!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups