SQL 触发器的编写问题

douliang 2002-08-15 07:03:16
现在要编写一个触发器在表Case上,触发的事件是delete.如果
deleted中一个字段ID(int 4)不为空(NULL)的话,就要删除表Link
中所有LID(int 4)等于该值的纪录。

注:delete是一条一条删除的

也不复杂阿,不过我是刚开始写触发器,判断deleted里的一个字段
是否为空----该怎么写?我查了一些T-SQL的语法,没有找到。

请大家帮帮我。
...全文
47 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
IronPromises 2002-08-16
  • 打赏
  • 举报
回复
BluePig(吹猪) :

AWP365 2002-08-16
  • 打赏
  • 举报
回复
delete from link where lid in (select id from deleted where id is not null )

你们写的我怎么刊布明白阿,能不能解释以下阿,我的这个行不行?
IronPromises 2002-08-15
  • 打赏
  • 举报
回复
呵呵,j9988,你也很快呀。和我是同一分钟的。
j9988 2002-08-15
  • 打赏
  • 举报
回复
对! is not null 可不写
j9988 2002-08-15
  • 打赏
  • 举报
回复
铁斑好快! 我的错了....
create trigger t1 on T_case
for deleted
as
delete from link a,deleted b where a.lid=b.id and b.id is not null
IronPromises 2002-08-15
  • 打赏
  • 举报
回复
and d.ID is not null
这个条件不写也可。
j9988 2002-08-15
  • 打赏
  • 举报
回复
create trigger t1 on T_case
for deleted
as
delete from link a,deleted b where a.lid=b.id and b.id<>null
caiyunxia 2002-08-15
  • 打赏
  • 举报
回复
CREATE TRIGGER tr_case_del ON [case]
FOR DELETE
if exists(select * from delete where id is not null)
delete from link where lid in (select id from deleted )
IronPromises 2002-08-15
  • 打赏
  • 举报
回复
......
delete l from Link l,deleted d
where l.LID = d.ID and d.ID is not null
......

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧