帮忙写一条触发器语句(因为急用)

qingyun27sc 2009-12-06 06:56:45
虽然请别人写语句这样不好,但是确实是有点急用。

有四张表
table_ID
table_information
table_family
table_grade


每个表中都有ID字段。

我想写一个触发器,比如在删除表table_ID的ID=12345的时候,其他表中的ID=12345那条记录也跟着删除 要怎么写呢?

谢谢帮忙 O(∩_∩)O~
...全文
44 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sgtzzc 2009-12-06
  • 打赏
  • 举报
回复
create trigger tri_delete_table_id
on table_id
for delete
as
delete table_information where id in(select id from deleted);
delete table_family where id in(select id from deleted);
delete table_grade where id in(select id from deleted);
go
破折号 2009-12-06
  • 打赏
  • 举报
回复

create trigger checkID on table_ID for delete
as
delete from table_information where ID=(select ID from deleted)
delete from table_family where ID=(select ID from deleted)
delete from table_grade where ID=(select ID from deleted)
SQL77 2009-12-06
  • 打赏
  • 举报
回复
级联就行了,

如果真的要

CREATE TRIGGER TRI_DEL ON table_ID
FOR DELETE
AS
BEGIN
DELETE table_information WHERE ID IN(SELECT ID FROM DELETED)
END

34,593

社区成员

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

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