Cannot insert into table because the table already exists?

glasnt picture glasnt · Jun 18, 2009 · Viewed 13.1k times · Source

I have a user table. I want to insert data into my user table.

I have a statement:

SELECT columna, columnb, 
INTO my_table 
FROM my_other_table
WHERE (... conditions ...)

I get the following error:

SQL Server Error on (myserver) Error:2714 at Line:1 Message:There is already an object named 'my_table' in the database.

Yes, thanks Sybase. I know this. I know the table exists. I want to insert data into it.

Why is Sybase not playing nicely? :(

(Sybase isn't my forte, Oracle is. This may just be an understanding issue, or lack there of. This would never happen in Oracle...)

Answer

Peter Radocchia picture Peter Radocchia · Jun 18, 2009

SELECT ... INTO is for creating new tables.

Use INSERT ... SELECT for existing tables. eg:

INSERT INTO my_table 
SELECT columna, columnb, 
FROM my_other_table
WHERE (... conditions ...)