带有现有记录的INSERT语句

Nic*_*ndo 3 sql sql-server-2005

我想知道是否可以使用已存在的记录执行insert语句.例如:

insert into tbl(item_name, item_price) values(select item_name, item_price from tbl where id = 5)
Run Code Online (Sandbox Code Playgroud)

说id是一个自动递增的pk.

当我尝试类似的东西时,我遇到了错误:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.
Run Code Online (Sandbox Code Playgroud)

我错过了什么,或者这是不可能的?

Fer*_*anB 6

查看本文:使用INSERT和SELECT添加行

无论如何,正确的方法如下:

insert into tbl(item_name, item_price) 
select item_name, item_price 
  from tbl 
 where id = 5
Run Code Online (Sandbox Code Playgroud)