--添加
create trigger InStudent
on Student
for insert
as
declare @id int
declare @name varchar(50)
select @id=id,@name=name from inserted
begin
insert dbo.BorrowRecord(sid,sname) values(@id,@name)
end
go
---修改
create trigger upStudent
on Student
for update
as
if update([name])
begin
update BorrowRecord set sname=i.[name] from BorrowRecord br, deleted d,inserted i
where br.id=d.id
end
--删除s
create trigger deStudent
on Student
for Delete
as
delete BorrowRecord from BorrowRecord br, deleted d
where br.sid=d.id