【发布时间】:2012-10-02 17:57:43
【问题描述】:
如何将行复制到select column1 value = 55的同一张表和column 1 value = 56的新行,如果我们第二次运行查询,它不应该再次复制旧行
【问题讨论】:
如何将行复制到select column1 value = 55的同一张表和column 1 value = 56的新行,如果我们第二次运行查询,它不应该再次复制旧行
【问题讨论】:
您可以添加一个where 子句来防止使用not exists 重复插入:
insert YourTable
(col1, col2, col3, ...)
select 56 -- New value
, col2
, col3
, ...
from YourTable
where col1 = 55 -- Old value
and not exists
(
select *
from YourTable
where col1 = 56 -- New value
)
【讨论】: