我如何用触发器来判断一个表是否表空? 前面部分略....select a from table2 where a=@tmp if 这个查询没有结果 begin insert into table1(a,b,c,d,e) select a,b,c,d,0 from inserted end 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select a from table2 where a=@tmp if 这个查询没有结果 begin insert into table1(a,b,c,d,e) select a,b,c,d,0 from inserted end不明白吗如果table2没有查询结果,则不用插入数据到table1中.如果找到相关的查询结果则插入数据到相关的表中. 首先要问打算在什么时候来判断表空的问题,例如是删除操作触发其次是问是前出发还是后触发,一般是后触发,那么直接用select count(*)或者其他普通判断即可啊如果是前触发,需要同时判断原表和inserted表是否有记录之后才是插入记录 我用update进行触发.我现在就想知道.如果table2没有查询结果,则不用插入数据到table1中.如果找到相关的查询结果则插入数据到相关的表中 if @@rowCount=0 insert into table1(a,b,c,d,e) select a,b,c,d,0 from inserted 或者是select @count=count(*) from table2 where a=@tmpif @count=0 insert into table1(a,b,c,d,e) select a,b,c,d,0 from inserted 求一简单问题的答案 Java 链接sqlserver数据库SelectMethod=cursor 一个字段可以本身即有单独索引也属于某联合索引之一吗? 求助sql server语句 怎么修改数据库默认用户名 一个让我头疼的问题 网贷源码谁用过?哪种的比较好?希望朋友告知 数据库语句查询问题,请各位大侠帮忙 access做的一个系统怎么把它原程序搞出来,做一些修改 各位 问一个想了 好久的问题,远程拨号更新数据库纪录! 我是菜鸟,谁帮我设计仓库的数据库,高分相赠 改版后:高手回来了吗?难道这个没有合理的解决办法了?
if 这个查询没有结果 begin
insert into table1(a,b,c,d,e)
select a,b,c,d,0 from inserted
end
不明白吗
如果table2没有查询结果,则不用插入数据到table1中.如果找到相关的查询结果则插入数据到相关的表中.
例如是删除操作触发
其次是问是前出发还是后触发,
一般是后触发,那么直接用select count(*)或者其他普通判断即可啊
如果是前触发,需要同时判断原表和inserted表是否有记录
之后才是插入记录
insert into table1(a,b,c,d,e) select a,b,c,d,0 from inserted
select @count=count(*) from table2 where a=@tmp
if @count=0
insert into table1(a,b,c,d,e) select a,b,c,d,0 from inserted