--创建测试表
create table student
(
stu_id int
,libraryCardNo varchar()
) create table borrowbook
(
b_id int
,libraryCardNo varchar()
) GO --插入测试数据
insert student
select ,''
insert borrowbook
select ,'' GO --查询数据
SELECT * FROM student
SELECT * FROM borrowbook --创建触发器<更新表>
create trigger stu_trg
on student
for update
as
declare @a varchar()
,@b varchar() select @a=libraryCardNo ,@b=stu_id from inserted
update borrowbook set libraryCardNo=@a where b_id=@b GO
--创建触发器<插入表>
create trigger insert_trg
on student
for insert
as
declare @a varchar()
,@b varchar()
select @a=libraryCardNo ,@b=stu_id from inserted
insert into borrowbook(b_id,libraryCardNo)values(@b,@a) GO --*********测试结果-----------------更改数据
update student set libraryCardNo='' where stu_id=
insert into student(stu_id,libraryCardNo)values(,'')
--结果对比
select * from student
select * from borrowbook