Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
By assertion, do you mean constraints, like CHECK constraints? – Craig Ringer Nov 8 '16 at 5:44
    
Yes, I mean like constraint. – nidipa dias Nov 8 '16 at 6:00
    
Yes, I asked the meaning like asserts – nidipa dias 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:

CREATE TRIGGER triggerName
AFTER UPDATE
    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.

share|improve this answer
    
can you example for asserts – nidipa dias Nov 8 '16 at 6:00
    
Can you give example for asserts? – nidipa dias Nov 8 '16 at 6:04
    
Refer this link classes.soe.ucsc.edu/cmps180/Winter08/trigger.html – Ganapathy Nov 8 '16 at 6:08
1  
@nidipadias: no relational DBMS today implements assertions - including Postgres – a_horse_with_no_name Nov 8 '16 at 6:53
    
@a_horse_with_no_name: I know that, but I want to know what is assert? when we use? and difference between assert and trigger. – nidipa dias Nov 8 '16 at 6:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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