Skip to content
Advertisement

Why my after update trigger is executing on insert although I have separate trigger for insert as well

Advertisement

Answer

First of all – for the INSERT – I would use a DATETIME2(3) column with a default constraint – then you do not need a trigger:

Now, each time you insert a row and you do not specify the dtEnter column in your list of columns to insert values into – it will automatically be set by SQL Server:

For the update, you need to use a trigger – can’t use a default constraint for that. Use this trigger – make sure to handle the fact that Inserted might contain multiple rows!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement