sql 删除触发器,每句话解释说明一下,谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/17 02:02:14
ALTER TRIGGER [trigCategoryDelete]
ON [dbo].[category]
instead of Delete
aS
BEGIN
declare @caId int
select @caId=id from deleted
delete comment where newsId in (select newsId from news where caId=@caId)
delete news where caId=@caId
delete category where id=@caid

END

ALTER TRIGGER [trigCategoryDelete] //修改触发器
ON [dbo].[category] //触发器作用在此表
instead of Delete //通常对于视图之类的删除操作
aS
BEGIN
declare @caId int
select @caId=id from deleted //声明两个变量,后者赋值为要删除视图的id
delete comment where newsId in (select newsId from news where caId=@caId) //删除指定id的行
delete news where caId=@caId
delete category where id=@caid //从news表,category 表删除指定记录

END