There would hardly be a database developer who hasn’t written triggers in their career. It is fairly common knowledge that you can have more than one trigger of the same type, i.e. INSERT/UPDATE/DELETE on the same table. Therefore, the following is perfectly valid:
~~~USE tempdb
GO
CREATE TABLE dbo.AppendTriggerTest (RowId INT IDENTITY(1,1),
RowValue VARCHAR(50)
)
GO
CREATE TRIGGER dbo.MainTrigger
ON dbo.AppendTriggerTest
FOR INSERT
AS
BEGIN
PRINT ‘<<<< INFO >>>> Main Trigger fired…’
END
GO
CREATE TRIGGER dbo.AppendTrigger
ON dbo.AppendTriggerTest
FOR INSERT
AS
BEGIN
PRINT ‘<<<< INFO >>>> Append Trigger fired…’
END
GO~~~
However, this was not the case in the days of SQL Server 6.5. In order to have a more than one trigger of the same type on the same table, the WITH APPEND clause needs to be used, which is effectively interpreted as AFTER. In the days of SQL Server 6.5, the trigger “AppendTrigger” will need to be defined as:
~~~CREATE TRIGGER dbo.AppendTrigger
ON dbo.AppendTriggerTest
FOR INSERT
WITH APPEND –NOTICE THE WITH APPEND CLAUSE HERE,
–DEPRECATED FROM SQL 2012 ONWARDS
AS
BEGIN
PRINT ‘<<<< INFO >>>> Append Trigger fired…’
END
GO~~~
Starting SQL Server 2012, the compatibility levels lower than 90 (i.e. SQL Server 2000 and below) are no longer supported. In accordance to this, the WITH APPEND clause has also been deprecated.
I assume that you are not using this in your production code, if you are, please upgrade! There is no workaround/alternate to this.
Reference:
- SQL 2000 Books-On-Line page for CREATE TRIGGER: http://msdn.microsoft.com/en-us/library/aa258254(v=sql.80).aspx
Until we meet next time,