Skip to content
Advertisement

Trigger after insert doesn’t work although all data is deleted

My table is empty and I’m trying to insert a record with the condition that the bit type column is not true, because the true condition can only be once for each country. Here is my trigger:

Advertisement

Answer

This line select @Pays = REL_PAYS from inserted is making the classic SQL Server trigger mistake – which is assuming there will only be a single row in the Inserted psuedo-table – when in fact there could be many.

You don’t really need the Inserted table to carry out your test. Instead just check the real table for any duplicates and if there are rollback.

What I think you want is:

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