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

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.

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 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.