A trigger is a statement or a block of statement which are executed automatically by the system when an event like insert, update or delete takes place on a table.

But I don't know where we use assertion and where we use trigger in database. Can anyone explain,

What is assertion and difference between the assertion and trigger?

  • By assertion, do you mean constraints, like CHECK constraints? – Craig Ringer Nov 8 '16 at 5:44
  • Yes, I mean like constraint. – nidipa nima Nov 8 '16 at 6:00
  • Yes, I asked the meaning like asserts – nidipa nima Nov 8 '16 at 6:01

The difference between triggers and assertions are:

Triggers - a trigger is a piece of SQL to execute either before or after an update, insert, or delete in a database.

An example of a trigger in plain English might be something like: before updating a customer record, save a copy of the current record. Which would look something like:

    INSERT INTO CustomerLog (blah, blah, blah)
    SELECT blah, blah, blah FROM deleted

Assertions - An assertion is a piece of SQL which makes sure a condition is satisfied or it stops action being taken on a database object. It could mean locking out the whole table or even the whole database.

Triggers - Triggers are more powerful because the can check conditions and also modify the data

Assertions - Assertions do not modify the data, they only check certain conditions.

Triggers - Triggers are linked to specific tables and specific events.

Assertions - Assertions are not linked to specific tables in the database and not linked to specific events.

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.