An AFTER INSERT trigger may not work correctly after you apply the fix documented in 975950

Applies to: Microsoft SQL Server 2005 Developer EditionMicrosoft SQL Server 2005 Enterprise EditionMicrosoft SQL Server 2005 Enterprise X64 Edition

Symptoms


Consider the following scenario:
  • You have an instance of either SQL Server 2005 or SQL Server 2008 or SQL Server 2008 R2.
  • On this instance you apply the hotfix documented in the following KB article
    975950FIX: Error message when you run an SSIS 2005 or SSIS 2008 package that uses the IBM DB2 OLE DB provider to export data to an IBM DB2 server: "The number of failing rows exceeds the maximum specified. Out of memory"
In this scenario, if you have a SSIS package that inserts data into a table using ‘Table or View’ direct access mode, an AFTER INSERT trigger having an UNION clause and defined on the destination table may insert only one row instead of multiple rows.

Cause


This occurs because SSIS incorrectly calls “SET ROWCOUNT 1” on the session that is executing the INSERT AFTER trigger. This causes the trigger to prematurely stop execution after it inserts the first row. 

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section of this article when you apply the fix documented in 975950. This hotfix is also included in the following updates:

  • 976951 Cumulative update package 7 for SQL Server 2005 Service Pack 3
  • 977444 Cumulative update package 9 for SQL Server 2008
  • 977443 Cumulative update package 6 for SQL Server 2008 Service Pack 1
  • 981355 Cumulative Update package 1 for SQL Server 2008 R2
So, the issue affects any builds of the respective product that contain this fix. You can use the following table as quick reference:
If you are on…Affected versionsAffected builds
SQL Server 2005 (SP3)(SQL 2005 SP3+CU7 for SP3) and later 9.00.4273 or later
SQL Server 2008 (RTM)(SQL Server 2008 + CU9 for SQL 2008) and later versions10.00.1828 or later
SQL Server 2008 (SP1)(SQL Server 2008 SP1+ CU6 for SP1) and later 10.00.2757 or later
SQL Server 2008 R2(SQL Server 2008 R2 + CU1 ) and later10.50.1702.0 or later




Resolution


To workaround the problem do the following in the OLE DB Destination editor:
  • Use 'Table or view - fast load' option. 
  • In the Advanced Editor dialog box, go to the Component Properties tab and in the FastLoadOptions add the value 'FIRE_TRIGGERS'

For additional information refer to the following topic in SQL Server Books Online:


More Information


Example: The following trigger uses UNION clause to inserts multiple rows in the destination table (MyTable) 

ALTER TRIGGER [dbo].[MyTrigger]
   ON  [dbo].[MyTable]
   AFTER INSERT AS
BEGIN
      SET NOCOUNT ON;
      INSERT INTO dbo.MyTable (x, y)
      SELECT 7 AS x, 7 AS y UNION
      SELECT 8 AS x, 8 AS y UNION
      SELECT 9 AS x, 9 AS y 
END
Because of the problem discussed in this article, when an SSIS package inserts any row into the table, the trigger only inserts the first row (7,7) and stops execution instead of inserting 3 rows.