Он проверяет, является ли кредитный рейтинг определенным значением, если его слишком низкий уровень вызывает ошибку и откатывает транзакцию.
--Declare a trigger with name `LowCredit` on table `Order`,
--run the trigger after
CREATE TRIGGER LowCredit ON Order
insert.
AFTER INSERT
AS
--start definition
--declare int
DECLARE @creditrating tinyint
--select from existing customer record the
-- inserted rows credit ranking (by custID)
-- inserted is the vt containing the changed rows
SELECT @creditrating = v.CreditRating
FROM Customer c INNER JOIN inserted i
ON c.custID = i.custID
--if lower than 5 roll back
IF @creditrating = 5
BEGIN
--raise error to the session
RAISERROR ('This customers''s credit rating
is too low to accept new orders.’)
--roll back transaction
ROLLBACK TRANSACTION
END