Writing constraint errors to SQL Error Log

Hello:

Is it possible to have constraint errors written to the SQL Error Log?

There are incidents when duplicate data is attempted to be inserted into a table with primary key constraint.

I would like to find when constraint errors are thrown and log them to the SQL Error Log for later proof to the developers.

Does this sound possible?

https://www.sommarskog.se/Short%20Stories/trace-exceptions.html

1 Like

On reflection I think I might have been reading too much.

The first thing I would probably do is have a look at the primary key. If it is some sort of increasing number you should try and find out how it is allocated. It should be done via an identity or a sequence.

I once came across a system where the developer thought it was fine just to get the MAX number and add one without even any attempt at locking and there was no PK or unqiue index defined in the schema. You can imagine the mess that started to produce! The quick fix was to get him to use a sequence and add the PK. I then ran quickly!

1 Like

Yes, there are defined primary keys on the tables that I would like to monitor within the database.

Thanks