Goods(g_id char(10) , g_quantity int )
Idents(i_id int,g_id char(10)) //g_id 是Goods的外码
create trigger quantity_enough
on Ident //订单表
for insert,update
as
declare @quantity int //商品表的商品数量
select @quantity=g_quantity from Goods where g_id=(select g_id from inserted)
if @quantity<=0
begin
print '商品数量不足,不能购买!操作已取消!'
rollback transaction
end
else
update Goods set g_quantity=@quantity-1 where g_id=(select g_id from inserted)
当我在订单表中插入一条记录时,只要有一个商品的数量不足,我就不能购买,
如果数量都足,商品表的商品数量都减去1,怎么回事?
------解决方案--------------------------------------------------------
select g_id from inserted
把这个结果集打印出来看看是什么