我有两个表,它们有相同的列id,但table1有更多的ids table2.现在我想找到那些id一中table1,但不存在table2,和insert他们进入table2,并设置其计数值为0.
我试过以下代码,但它说syntax error, unexpected IF.任何人都可以帮我搞清楚吗?非常感谢.
if not exists(select * from table1 where table1.id = table2.id)
begin
insert into table2 (id, count) values (table1.id, 0)
end
Run Code Online (Sandbox Code Playgroud)