0

Hi,

I want to copy records of a table say employee into the same table.
For Example Table Employee contains 5 records.
So i want to insert the same 5 records again into the same table Employee 20 times.
I have tried the following Query (which is inserting records in another table) :

DECLARE @intFlag INT SET @intFlag = 1 WHILE (@intFlag <=20) BEGIN SELECT * INTO table2 FROM table1 SET @intFlag = @intFlag + 1 END GO

If i am copying records into the same table then
Error is displayed :

There is already an object named table1 in the database

3
Contributors
2
Replies
25
Views
4 Years
Discussion Span
Last Post by adam_k
0

You are getting that error because there is a primary or unique key in your table and by using this procedure you are inserting same value for that and that's what giving you this error.Use autoincrement for primary field and instead of getting all data,get all data except primary key and try to insert data using procedure.

0

I disagree with IIM.
The select into is used when you want to select records into a new table (it is created by the into).
If you want to insert into an existing table, your syntax should be like:

Insert into table1
(field1,field2,field3)
select field1, field2,field3
from table2 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.