作业帮 > 综合 > 作业

如何定义一个触发器我想删除数据库表中的记录,但是表中有与外表关联的字段,要删除这条记录,并把相关表的记录一起删除,想创建

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 16:26:24
如何定义一个触发器
我想删除数据库表中的记录,但是表中有与外表关联的字段,要删除这条记录,并把相关表的记录一起删除,想创建一个触发器,请给一个实例,或触发器代码
--创建触发器删除时,删除对应的全部字段
CREATE TRIGGER Delete_Group ON [GroupPerson] --要创建的触发器名称和作用在GroupPerson表上
FOR DELETE
AS
declare @AutoId int --定义删除参数AutoId(唯一ID)
select @AutoId = AutoId from deleted --参数赋值
delete from Group_TextTemp where GroupId = @AutoId --删除临时保存内容表
delete from Group_Ad where GroupId=@AutoId --删除广告表内容
delete from Group_Img where GroupId=@AutoId --删除图标表内容
delete from Group_BBS where GroupId=@AutoId --删除问答表内容
delete from GuaranteeOrder where GroupId=@AutoId --删除订单表内容
Go