【简答题】 请为以下代码加上注释。 create trigger tr_delete on student for delete begin declare @bh char(5) select @bh=deleted.sno from deleted delete from studentcourse where sno=@bh end
时间: 2023-11-22 15:55:30 浏览: 129
当时自己初学SQL时,对游标很难理解,现在编写了一个实例游标循环,到时写SQL循环时方便些
```
-- 创建名为tr_delete的触发器,当对student表进行删除操作时触发
create trigger tr_delete
on student
for delete
begin
-- 声明一个变量@bh,类型为char(5)
declare @bh char(5)
-- 从被删除的记录中获取sno字段的值,并赋值给@bh变量
select @bh=deleted.sno from deleted
-- 在studentcourse表中删除sno等于@bh变量的记录
delete from studentcourse where sno=@bh
end
```
阅读全文