Cannot insert into table because the table already exists?

二次信任 提交于 2019-12-05 00:07:10

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

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.

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.

Rajesh

Use 'existing' keyword after 'into' to insert in existing table.

SELECT [COLUMN LIST] INTO EXISTING [TABLE NAME]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!