Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL SELECT INTO query with a Join, Error "There is already an object named '*****' in the database."

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.

like image 940
James O Brien Avatar asked Jun 22 '12 10:06

James O Brien


People also ask

How do you fix there is already an object named in the database?

Right-click on the database, go to Advanced, and select SQL Database Cleanup Wizard. The SQL Cleanup Wizard will then run. If there are no objects to clean up you will get a message saying there was nothing found.

What does select * from do?

An asterisk (" * ") can be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include: The FROM clause, which indicates the table(s) to retrieve data from.

What does select into do?

The SELECT INTO statement copies data from one table into a new table.


2 Answers

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
like image 180
phillyd Avatar answered Sep 29 '22 10:09

phillyd


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
like image 32
Shaikh Farooque Avatar answered Sep 29 '22 08:09

Shaikh Farooque