How to duplicate the records of a table in the BD

Asked

Viewed 5,466 times

3

Well I have a BD with some records. And I would like that amount of records to duplicate. I don’t want to double loop to show the double amount, I would literally duplicate all the records in the table. Is there any way to accomplish this?

2 answers

6


Friend makes an Insert and in Voce values makes a select, thus:

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.

I hope it helps. []’s

6

Use a insert along with a select, the types of data in the select and in the insert should be the same or compatible it is also possible to use other clauses as where, joinetc.

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

Insert select syntax

  • Should be placed in place of C1 of SELECT, the value Null if, only if, C1 is the primary key of the bank, otherwise there will be an error when trying to duplicate id.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.