0

Sql newbie in need of help.

I have a table with an SQL trigger that occurs on Insert. It looks like this:

ALTER TRIGGER Holiday_ITrig
ON HolidayDate
FOR INSERT
AS
IF NOT EXISTS (
                SELECT
                        ID
                    FROM
                        WorkingDay w
                    INNER JOIN
                        inserted i ON
                            w.ID = I.WorkingDayId
                    WHERE
                        WorkingDayTypeId = 2
                )
BEGIN
    ROLLBACK TRANSACTION
END

However, I also need the trigger to fire on update. Is this possible within the same trigger or do I have to create a new 'update' trigger?

4

1 回答 1

2

只需添加UPDATE到操作列表中。

您将需要检查相同的逻辑是否适用于 UPDATE 以及原始 INSERT。

ALTER TRIGGER Holiday_ITrig
ON HolidayDate
FOR INSERT, UPDATE
AS
IF NOT EXISTS (
                SELECT
                        ID
                    FROM
                        WorkingDay w
                    INNER JOIN
                        inserted i ON
                            w.ID = I.WorkingDayId
                    WHERE
                        WorkingDayTypeId = 2
                )
BEGIN
    ROLLBACK TRANSACTION
END

创建触发器 MSDN 文章

于 2013-06-17T08:51:48.773 回答