I'm writing a trigger to write audit data to my table, it automatically inserts the LastModifiedID and LastModified date into fields on that table.
I've put a Not NULL constraint on the LastModifiedID and LastModified columns.
The problem is that a simple insert into the other columns (not the LastModified columns) fails with a "fields can't be null". I was expecting the trigger to take care of the insertion of data into the LastModified columns (the trigger code does this) and therefore to satisfy the Not Null constraint.
My conculsion is that the Not Null constraints are checked BEFORE the trigger runs so my normal insert (which doesn't insert into the LastModified columns directly) fails before the trigger has a chance to insert into the LastModified columns.
Is that the right conclusion? Any suggestions? Obviously I can remove the Not Null constraint but that just doesn't feel right.
Thanks!
- Gary
I've put a Not NULL constraint on the LastModifiedID and LastModified columns.
The problem is that a simple insert into the other columns (not the LastModified columns) fails with a "fields can't be null". I was expecting the trigger to take care of the insertion of data into the LastModified columns (the trigger code does this) and therefore to satisfy the Not Null constraint.
My conculsion is that the Not Null constraints are checked BEFORE the trigger runs so my normal insert (which doesn't insert into the LastModified columns directly) fails before the trigger has a chance to insert into the LastModified columns.
Is that the right conclusion? Any suggestions? Obviously I can remove the Not Null constraint but that just doesn't feel right.
Thanks!
- Gary