16

I'm currently trying to copy data from table into another by using a SELECT INTO query. But Im receiving an error in SQL Server.

"Msg 2714, Level 16, State 6, Line 2 There is already an object named 'Product' in the database."

Im still very new to sql. This is the SQL script I've created to do the job.

BEGIN TRANSACTION
SELECT d.[PDate]
      ,d.[SDate]
      ,d.[UseDRM]
      ,d.[CreatedBy]
      ,d.[CreatedDate]
      ,d.[UpdatedBy]
      ,d.[UpdatedDate]
INTO [******].[dbo].[Product]
FROM [******].[dbo].[ProductTypeData] AS d
JOIN [******].[dbo].[Product] AS t
ON d.ProductTypeDataID = t.ProductTypeDataID
ROLLBACK TRANSACTION

I have already created these column in the destination table but they are currently empty. Any help is greatly appreciated.

James O Brien
  • 217
  • 1
  • 3
  • 10
  • 1
    SQL is a language. Given the error message, I've *guessed* you're on SQL Server and added that tag. If incorrect, please edit your tags to indicate which database product you're using. – Damien_The_Unbeliever Jun 22 '12 at 10:55

2 Answers2

29

SELECT INTO is used to create a table based on the data you have.

As you have already created the table, you want to use INSERT INTO.

E.g.

INSERT INTO table2 (co1, col2, col3)
SELECT col1, col2, col3
FROM table1
phillyd
  • 752
  • 9
  • 14
  • 2
    Yesterday I found your solution and gratefully used it. Today I did the same mistake again, wondering how I did it yesterday, I googled and came to your answer again. Would upvote it a second time! :)) – rinukkusu Feb 24 '17 at 12:00
4

Select Into is used to create the new table.

Instead of that you can use

INSERT INTO table1 (col1, col2, col3)
SELECT col1, col2, col3
FROM table2
Shaikh Farooque
  • 2,520
  • 1
  • 17
  • 30