Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

blindman stumped by trigger and identity issue.

$
0
0
The blindman is totally stumped!

I've run into a situation that looks absolutely crazy to me. Makes no sense at all.

We're trying to replicate some data tables, which means they must have primary keys. Two tables do not have natural key candidates. They contain duplicate records. So I added an identity column to the end of each table.
These tables each have triggers on them for creating records in matching audit tables. I modified the triggers to enumerate the columns, and the one of the tables works fine. The second table does not. The trigger fires and populates the audit table for manual edits, but attempting to inserts record through the application does not work. The application fails to insert records to either the primary or the audit table.

So to debug, I backed out a ways, and then started adding bits and pieces while continuous testing:

Overview:
The application inserts to table A.
A trigger on table A inserts to table B.

Tests:
Added nullable int column "ID" to table B.
---Manual inserts to table A work. Audit records are created in table B.
---Application inserts to table A work. Audit records are created in table B.

Changed ID to non-nullable, default 1.
---Manual inserts to table A work. Audit records are created in table B.
---Application inserts to table A work. Audit records are created in table B.

Changed ID to identity column.
---Manual inserts to table A work. Audit records are created in table B.
---Application fails to insert to either table A or table B.

Changed ID to GUID, default newid().
---Manual inserts to table A work. Audit records are created in table B.
---Application inserts to table A work. Audit records are created in table B.

So what gives? What could possibly cause an application to prevent an identity value from being generated in a table that it does not touch, on a column that it knows nothing about?

Any suggestions?

Viewing all articles
Browse latest Browse all 13329

Trending Articles