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

这两个表触发器如何写

wsq1168 发布于 2007-12-13 17:17, 1120 次点击
当借书发生时,到期日=借书日+可借天数自动生成 触发器如何写
create table bookclassinformation --书的种类
(
    bookclass_id char(10) primary key ,--书种类ID
    bookclass_name nvarchar(50) not null,--书种类名称
    bookborrowday int ,--可借天数
)
create table  bookborrow--借阅图书
(
    bookborrow_id int primary key,
    book_ISDN char(20) ,--书编号
    member_id char(10) ,--会员编号    
    book_borrowdate smalldatetime,--借书日
    book_maturedate smalldatetime,--到期日    
    book_estate varchar(10),
)
2 回复
#2
西风独自凉2007-12-13 18:54
下面不是有嗎?自己參照著寫一下,這樣才會有進步。
#3
nhlzh87082007-12-13 21:04
小小愚见
本人也是个菜B...刚看了你的题写了一下这触发器...

首先本人在book_borrowdate列添加了一个default 约束
alter table bookborrow
add constraint df_borrowdate default (getdate) for book_borrowdate

然后就开始写触发器的代码
create trigger maturedate
on bookborrow
after insert
as
update bookborrow
set book_maturedate=(select book_borrowdate from inserted)+
(select bcf.bookborrowday from bookclassinformation bcf
where  bcf.bookclass_id=(select book_isdn from inserted))
where book_isdn=(select book_isdn from bookborrow)

[[italic] 本帖最后由 nhlzh8708 于 2007-12-13 21:05 编辑 [/italic]]
1