How to duplicate the records of a table in the DB

3

Well I have a DB with some records. And I would like that amount of records to double. I do not want to do double looping to show double quantity, I would literally duplicate all the records in the table. Is there any way to accomplish this?

    
asked by anonymous 24.06.2014 / 17:34

2 answers

6

Friend makes an insert and in values you make a select, like this:

INSERT INTO [Database].[dbo].[Table]
       ([Coluna1]
       ,[Coluna2])
 select Coluna1, Coluna2 from Table
GO

This will duplicate your table, as it will insert everything that already exists in your table.

Hope it helps. [] 's

    
24.06.2014 / 17:41
7

Use insert together with select , data types in select and insert must be the same or compatible, it is also possible to use other clauses like where , join etc

INSERT INTO tabela(c1, c2, c3) SELECT c1, c2, c3 FROM tabela

insert select syntax

    
24.06.2014 / 17:42