以上功能不建议使用触发器
1. 插入时判断表中是否已存在该条记录..,如果一定要使用触发器,以下类似,供参考CREATE TRIGGER tri_books_insert ON books
for insert
as
begin
if exists (select 1 from books a,inserted b where a.bookName=b.bookName)
begin
update...
end
else
begin
insert...
end
end 2. update books set bookAmount=bookAmount-1 where bookAmount>0
1. 插入时判断表中是否已存在该条记录..,如果一定要使用触发器,以下类似,供参考CREATE TRIGGER tri_books_insert ON books
for insert
as
begin
if exists (select 1 from books a,inserted b where a.bookName=b.bookName)
begin
update...
end
else
begin
insert...
end
end 2. update books set bookAmount=bookAmount-1 where bookAmount>0
表中有这样一条记录:Java JDK实例宝典 978-7-121-03651-4 79 夏先波 电子工业出版社 2008-1-24 计算机/程序设计 2
当我再插入一条记录时
insert into books select 'Java JDK实例宝典' ,'978-7-121-03651-4',79,'夏先波','电子工业出版社','2008-1-24','计算机/程序设计', 8
现在表中共有'Java JDK实例宝典' 10本(8+2)第二个条件很简单 当我借一本书时,表中的某本书就少了一本,当该书被借完(即数量为0时),就不能再借了
用语句是这样的--update books set bookAmount=bookAmount-1 where bookName=……