All pastes #942992 Raw Edit

Lakario

public sql v1 · immutable
·published 2008-03-14 21:43 UTC
rendered paste body
-- 10 only where alcoholicDrinkType = 'Wine'create trigger tr_WineAward_DrinkTypeon WineAwardafter insert, updateas	if not exists (select * from MenuItem as mi 				join INSERTED as i on mi.itemNr = i.itemNr				where mi.alcoholicDrinkType = 'Wine' and mi.itemNr = i.itemNr)	begin		raiserror ('WineAward cannot be designated to items that are not alcoholicDrinkType Wine.', 16, 1)  		rollback Transaction 	endgo-- 11 only where alcoholicDrinkType = 'Wine'create trigger tr_WineSupply_DrinkTypeon WineSupplyafter insert, updateas	if not exists (select * from MenuItem as mi 				join INSERTED as i on mi.itemNr = i.itemNr				where mi.alcoholicDrinkType = 'Wine' and mi.itemNr = i.itemNr)	begin		raiserror ('WineSupply cannot be designated to items that are not alcoholicDrinkType Wine.', 16, 1)  		rollback Transaction 	endgo-- 12 frequency of WineSupplycreate trigger tr_WineSupply_Frequencyon WineSupplyafter insert, updateasif Update (itemNr)	if((select count(*) from WineSupply where itemNr = (select itemNr from inserted)) > 3)	begin		raiserror ('There cannot be more than 3 WineSupply entries with the same itemNr.', 16, 1)  		rollback Transaction 	end-- 13 lineitem = quantity * pricecreate trigger tr_LineItem_LineTotal on LineItemafter insert, updateasif Update (lineTotal)	declare @unitPrice money	declare @quantity int	declare @total money	set @unitPrice = (select unitPrice from INSERTED)	set @quantity = (select quantity from INSERTED)	set @total = @unitPrice * @quantity	if not exists (select * from inserted where lineTotal = @total)	begin		raiserror ('Value inserted for lineTotal was incorrect.', 16, 1)  		rollback Transaction 	endgo