0

Table DDL:

CREATE TABLE trigtest(a INTEGER IDENTITY(1,1) PRIMARY KEY, b INT)

I currently have

CREATE TRIGGER MaxDelete ON trigtest INSTEAD OF DELETE AS
IF @@rowcount < 1000
DELETE trigtest  WHERE a IN (SELECT a FROM deleted)

However, it requires me to write the last line in a customized manner for every table I apply it to

Instead of the above, is it possible to write something of the sort:

IF @@rowcount > 1000 (OR SELECT COUNT(*) FROM DELETED)
Kill statement
ELSE
Continue statement
  • 2
    Did you try ROLLBACK TRANSACTION;? – Aaron Bertrand Feb 2 '15 at 11:42
  • Just tried on your suggestion and it works :) – Akash Feb 2 '15 at 11:45
3
IF @@ROWCOUNT > 0
BEGIN
   ROLLBACK TRANSACTION;
END
ELSE
BEGIN
  ... continue ...
END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.