Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Insert / update triggers not working after upgrade

$
0
0

I recently moved a database from a SQL server 2005 box to new server running SQL server 2012. The update/insert triggers that were working on the tables to handle referential integrity checking are no longer working. Running the same database on SQL Server 2008 and everything works.

Here is one of the trigger that throws the error 44446

USE[M2Data]

GO

/****** Object: Trigger [dbo].[tblContacts_UTrig]    Script Date: 3/11/2014 9:07:13 AM ******/

SETANSI_NULLSON

GO

SETQUOTED_IDENTIFIERON

GO

ALTERTRIGGER[dbo].[tblContacts_UTrig]ON[dbo].[tblContacts]FORUPDATE AS

SETNOCOUNTON

/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tblCompanys' */

IFUPDATE(CompanyId_Cn)

   BEGIN

       IF (SELECTCOUNT(*) FROMinserted)!=

          (SELECTCOUNT(*) FROMtblCompanys,insertedWHERE (tblCompanys.CompanyID_Co=inserted.CompanyId_Cn))

           BEGIN

               RAISERROR 44446 'The record can''t be added or changed. Referential integrity rules require a related record in table ''tblCompanys''.'

               ROLLBACKTRANSACTION

           END

   END

I have verified that there is a matching key in tblCompanys.  Also, when I run a query to update tblContacts the error message appears but the update does take.  If I try and edit the row directly by selecting edit top 200 rows - the error message appears and the update does NOT take.

These triggers were probably added to the database during an upsize from MS Access to SQL Server 7 way back. 

What am I missing - is it something in the syntax?  thank much for any and all help.



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>