DATABASE MANAGEMENT SYSTEM

Assertions in DBMS

Assertions are logical conditions or predicates that are specified to the database and are expected to be true at all times. They are used to enforce business rules or other conditions on the data in the database. Assertions are typically defined using a declarative language such as SQL and are checked by the DBMS to ensure that they are always true. If an assertion is violated, it indicates a data integrity issue.

Example:The number of employees with a salary greater than 0 is equal to the total number of employees in the "Employees" table. If this condition is ever false, it means there is a violation of the assertion.

It's important to note that not all database management systems support assertions, and their usage can depend on the specific DBMS being used.

Triggers in DBMS:

Triggers are special types of stored procedures that are automatically executed (or "triggered") in response to specific events in the database. These events could include insertions, updates, or deletions of data. Triggers are used to enforce complex business rules, maintain data integrity, or log changes to the database.

There are two main types of triggers:

  • Before Triggers (or INSTEAD OF Triggers):
    • Executed before the triggering event (e.g., before an INSERT, UPDATE, or DELETE statement).
    • Can be used to modify the data or prevent the triggering event from occurring.
  • After Triggers:
    • Executed after the triggering event.
    • Often used for actions such as updating additional tables, logging changes, or sending notifications.