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
  • 2
    Did you try ROLLBACK TRANSACTION;? Commented Feb 2, 2015 at 11:42
  • Just tried on your suggestion and it works :)
    – Akash
    Commented Feb 2, 2015 at 11:45

1 Answer 1

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 and acknowledge you have read our privacy policy.

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