Programming in MS SQL Server 2012 |
ALTER TriggerThe following example alters existing DML trigger in EBusiness database. This trigger prints a user-defined message to database or application user, when tries to INSERT or UPDATE a record with invalid product expiry date in Product table. --
Example 134 -- USE EBusiness GO
ALTER TRIGGER dbo.DMLProductTableTrigger ON
dbo.Product AFTER INSERT, UPDATE AS IF EXISTS
(
SELECT * FROM dbo.Product
WHERE
Exp_Date <= GETDATE()
)
BEGIN
RAISERROR ('The Product Expiry Date is
less than or equal to System Date', 16, 1)
ROLLBACK
TRANSACTION
RETURN
END GO --
Example 135 -- INSERT INTO Product VALUES ('TP03','Product TP C',12345,'12-31-2010',15,'Remark TP C') UPDATE Product SET Exp_Date = '12-31-2010' WHERE Prod_Code = 'TP01' |
* * * * *