I'm trying to learn triggers in mssql and have a problem with two that I'm working on.
Both are using the table "Orders"
1. Not allowing a batch insert or update statement to be run.
2. If a user enters or updates the ShippedDate field, and provides a value that is before the OrderDate field, it will be blocked (rolled back), and prints a warning message.
Any help would be greatly appreciated... been working on this for a few hours now :(.
Question
DeathLace
Hi,
I'm trying to learn triggers in mssql and have a problem with two that I'm working on.
Both are using the table "Orders"
1. Not allowing a batch insert or update statement to be run.
2. If a user enters or updates the ShippedDate field, and provides a value that is before the OrderDate field, it will be blocked (rolled back), and prints a warning message.
Any help would be greatly appreciated... been working on this for a few hours now :(.
---------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE:
I got #2... just don't know how to block a batch insert :(....
CREATE TRIGGER checkDate ON dbo.Orders
AFTER INSERT, UPDATE
AS
declare @sd datetime
declare @od datetime
SELECT @sd = (select ShippedDate from inserted)
SELECT @od = (select OrderDate from inserted)
IF (@sd < @od)
BEGIN
ROLLBACK TRAN
raiserror ('Please choose a shipped date that is after the order date', 16, 1)
END
Was my answer for #2... I assume this is right.
Link to comment
Share on other sites
4 answers to this question
Recommended Posts