Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server copy all rows from one table into another i.e duplicate table

I want to keep a table as history and replace it with an empty one. How can I do this through Management Studio?

like image 509
iamjonesy Avatar asked Apr 22 '10 13:04

iamjonesy


People also ask

How do you replicate rows in SQL?

To select duplicate values, you need to create groups of rows with the same values and then select the groups with counts greater than one. You can achieve that by using GROUP BY and a HAVING clause.

How do I copy a row from one SQL Server database to another?

A simple way is to open SSMS and Right click on database and go to Tasks > Import Data and follow the wizard to set source and destination.


2 Answers

Duplicate your table into a table to be archived:

SELECT * INTO ArchiveTable FROM MyTable 

Delete all entries in your table:

DELETE * FROM MyTable 
like image 137
froadie Avatar answered Sep 21 '22 03:09

froadie


Don't have sql server around to test but I think it's just:

insert into newtable select * from oldtable; 
like image 21
Hans Olsson Avatar answered Sep 20 '22 03:09

Hans Olsson