SQL for MS SQL Server

Previous Next

MS SQL Server differs from other RDBMS types in the way NULL values are handled. This can have an effect when writing constraints. (e.g. if you want to port).

On MS SQL Server, the following is sufficient to ensure that a constraint is only evaluated in case of UPDATES:

WHERE    OLD( column ) !=  column

 

However, for transparency you are advised to write:

WHERE    OLD( column ) !=  column

AND      OLD( primary-key-column ) IS NOT NULL

AND      primary-key-column IS NOT NULL

 

The first AND clause ensures that INSERTS are excluded, the second AND clause ensures that DELETES are excluded.