0

Can we possible to call truncate command inside trigger using sql server?

3
  • 2
    Surely as quick to try it as post a question Commented Jan 31, 2022 at 8:16
  • 1
    Yes, you can. Better question is why would you want to... Commented Jan 31, 2022 at 9:42
  • @Charlieface You can delete faster with truncate. As an example to delete history in a tracking table, everytime one row is added to a dba table to oversee who is working... Do not forget that TRUNCATE is an operation that does'nt fire the trigger DELETE... Whch can be interesting for certain use cases. Commented Jan 31, 2022 at 10:07

1 Answer 1

2

TRUNCATE command is a transactional command and all the pages deleted will be writed into the transaction log. And because the trigger code is envolved in a transaction, you can ROLLBACK or COMMIT the implicit transaction into the trigger code (COMMIT is not a good practice into trigger code).

So, yes, you can !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.