Trigger Dbms
Trigger Dbms
EXAMPLE:
Imagine you have a database with tables Orders and Order_Items. Whenever an order is placed (INSERT operation
into the Orders table), you want to perform certain actions automatically:
Key Points:-
1. Purpose:-
• Assertions are used to enforce specific business rules, integrity constraints, or conditions on the data stored in the
database.
2. Implementation:-
• Typically written in SQL using the CREATE ASSERTION statement to define the condition.
• An assertion can reference one or more tables and their columns, specifying a condition that must not be violated.
3. Enforcement:
• Assertions are checked whenever data is modified (inserted, updated, or deleted) to ensure the defined conditions
are met.
• If the condition defined in the assertion is violated by an operation, the database system prevents the operation
from executing, ensuring data consistency and integrity.
4. Usage:
• Assertions are especially useful when integrity constraints or business rules cannot be fully expressed using other
constraints like primary keys, foreign keys, or check constraints.
5. Maintenance:
• Regular review and modification of assertions might be necessary as business rules evolve or data requirements
change over time.
Example:
Consider an assertion in an employee database ensuring that the salary of an employee should be within a certain
range:
CREATE ASSERTION SalaryRangeCheck
CHECK (Salary BETWEEN 30000 AND 100000);
This assertion ensures that any salary inserted or updated in the database falls within the specified range.
Assertions complement other integrity constraints in maintaining data accuracy, preventing inconsistencies, and
ensuring compliance with business rules. They play a significant role in ensuring data integrity by verifying that the
database adheres to specific conditions or rules that aren't easily expressed using traditional constraints.
The “Division" operation is a fundamental concept used in relational algebra to retrieve specific information based on a
particular condition or set of conditions. It's different from typical arithmetic division and involves sets or relations.
The division operation is primarily used when dealing with relationships between tables or relations in a relational
database. It's commonly used in scenarios where you need to find records that match a certain condition across multiple
tables.
Let's say you have two relations, R and S, and you want to find all the tuples in R that are associated with all tuples in S. This
operation is represented in relational algebra as:
R÷S
The division operation in relational algebra is complex and not directly supported in SQL as a separate operator. However, it
can be achieved using various SQL constructs like joins, subqueries, and NOT EXISTS or NOT IN clauses.