注册 登录
编程论坛 SQL Server论坛

这两个表如何写触发器

wsq1168 发布于 2007-12-12 20:45, 1470 次点击
当借阅发生时,在书的信息表里的现存量自动减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,--书的信息
   
)
5 回复
#2
西风独自凉2007-12-13 08:52
很簡單的一個trigger....
#3
wsq11682007-12-13 12:58
给写一个
给写一个
#4
purana2007-12-13 13:17
create trigger tr on bookborrow
for insert
as
    update a
    set book_residual =book_residual -1
    from bookinformation a,inserted b
    where a.book_ISDN=b.book_ISDN
go
#5
purana2007-12-13 13:18
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
#6
good_good_study2007-12-17 08:46
book_ISDN char(20) ,--书编号

为什么在“书的信息”表中是book_ISDN  nvarchar(50) primary key -书ISDN  

两个类型不一样啊
1