views:

1006

answers:

3

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...)

+2  A: 

Have you tried it this way around?

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

It appears that it is trying to implicitly create a new table for you called my_table.

Tetraneutron
+4  A: 

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 ...)
Peter
yes, this describes the problem, and the solution
BlackTigerX
Oh I see... That's interesting to know. Never knew you could do that in Sybase. Cheers, Peter.
glasnt
+1  A: 

Not sure of SYBASE but in DB2 this works for me


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

I think its safer to specify the columns in the insert statement as well rather than assume they'll be in the same order as the select.

MadMurf