这两个表如何写触发器
当借阅发生时,在书的信息表里的现存量自动减1,用触发器如何实现create table bookborrow--借阅图书
(
bookborrow_id int primary key,
book_ISDN char(20) ,--书编号
member_id char(10) ,--会员编号
book_borrowdate smalldatetime,--借书日
book_maturedate smalldatetime,--到期日
book_num smallint,--借书数量
)
create table bookinformation--书的信息
(
book_ISDN nvarchar(50) primary key ,--书ISDN
book_name nvarchar(50)not null,--书名
bookclass_id int not null,--数类别
book_writer nvarchar(20)not null,--书作者
bookpublish_time datetime not null,--书发行时间
bookpublisher nvarchar(20),--书发行者,
book_money money not null,--书的价格
book_amount smallint,--库存总量
book_residual smallint,--现存量
book_information ntext,--书的信息
)
给写一个
给写一个 create trigger tr on bookborrowfor insert
as
update a
set book_residual =book_residual -1
from bookinformation a,inserted b
where a.book_ISDN=b.book_ISDN
go create trigger tr on bookborrow
for insert
as
update a
set a.book_residual =a.book_residual -1
from bookinformation a,inserted b
where a.book_ISDN=b.book_ISDN
go book_ISDN char(20) ,--书编号
为什么在“书的信息”表中是book_ISDN nvarchar(50) primary key -书ISDN
两个类型不一样啊
页:
[1]
