日期:2014-05-18 浏览次数:20549 次
ALTER TABLE PurchOutProduct ADD CONSTRAINT ck_qty_PurchOutProduct CHECK (qty >=0); GO ALTER TABLE PurchOutbase ADD CONSTRAINT ck_qty_PurchOutbase CHECK (qty >=0); GO
------解决方案--------------------
用检查就行了 Create table PurchOutProduct( Qty int check (Qty>0) )
------解决方案--------------------
触发器这样实现
Create table PurchOutProduct( Qty int ) go Create trigger tr_PurchOutProduct on PurchOutProduct for insert as if exists(select 1 from inserted where Qty<=0) rollback tran
------解决方案--------------------
Create trigger tr_PurchOutProduct on PurchOutProduct for insert as insert into PurchOutProduct select * from inserted where not exists (select 1 from inserted where qty<0)