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