I have a trigger that check data before insert to another table
IF NOT EXISTS (SELECT *
FROM inserted,
Clients
WHERE Inserted.Account = Clients.Account)
BEGIN
INSERT INTO Clients(GUID, Account, ....)
SELECT GUID, Account
FROM inserted
END
it’s working fine if one row updated
but if use batch update its not working.
for example Update Table1 set Number = Number where account <> ''
If the second table (Clients) is not empty, nothing added
if it’s empty its work well
Rather than doing a check then insert, why not write it as a single
INSERTstatement:The
NULLcheck in theWHEREclause can be for any column inClientswhich isn’t nullable.Even if you keep the
EXISTScheck in, you still need something like the above, because theEXISTScheck is asserting something about all of the rows ininserted– when it may consist of some rows for which the assertion is true, and some rows for which it is false.