我想将行从一个表移动到另一个表,delete from [foo] output deleted.[col] into [bar] (col)
看起来是一个不错的选择。插入删除的数据,加上一些硬编码的值,输出语句
但列不相同。所以我想插入一些硬编码的值(理想的编程决定的值)到目标表中。
我设置了几张表来演示。
create table delete_output_test (
thing1 int not null,
thing2 varchar(50),
thing3 varchar(50)
)
create table delete_output_test2 (
thing1 int not null,
thing2 varchar(50),
thing3 varchar(50),
thing4 int
)
insert into delete_output_test values (0, 'hello', 'world'),
(1, 'it''s', 'me'),
(2, 'i', 'was'),
(3, 'wondering', 'if')
现在从一个表移动到罚款,如果我不是太贫穷的另一个作品...
delete from delete_output_test2
output deleted.thing1,
deleted.thing2,
deleted.thing3
into delete_output_test
(thing1,
thing2,
thing3)
但如果我要来填充最后一列是什么?
delete from delete_output_test2
output deleted.thing1,
deleted.thing2,
deleted.thing3
into delete_output_test
(thing1,
thing2,
thing3,
4)
附近有语法错误 '4'。期待'。',ID,PSEUDOCOL或QUOTED_ID。
我对SQL相当陌生,所以我甚至不确定这些东西是什么。
那么,为什么我不能硬编码插入的值?或者,如果我想变得聪明,甚至用4
替换一些select
声明?
我不知道为什么它没有发生,我尝试。谢谢! – mac9416
@ mac9416乐意帮忙! – SqlZim
好吧,那很酷。 –