Database Management System & Rdbms| Trigger in sql | Malayalam Tutorial

3 min read 4 hours ago
Published on Oct 21, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial provides a comprehensive overview of Database Management Systems (DBMS) and Relational Database Management Systems (RDBMS) focusing on SQL triggers. It is designed for students and professionals looking to understand the fundamentals of database management and the practical application of triggers in SQL, particularly in the context of a Malayalam-speaking audience.

Step 1: Understanding Database Management Systems

  • Definition: A Database Management System is software that allows users to create, manage, and manipulate databases.
  • Types:
    • DBMS: A general term for database management systems that may not support relationships between data.
    • RDBMS: A type of DBMS that stores data in a structured format using rows and columns, allowing for relationships between tables.

Key Features of RDBMS

  • Data is stored in tables.
  • Supports ACID (Atomicity, Consistency, Isolation, Durability) properties.
  • Allows for complex queries using SQL.

Step 2: Introduction to SQL

  • SQL (Structured Query Language): The standard programming language used to manage and manipulate databases.
  • Common SQL Commands:
    • SELECT: Retrieve data from a database.
    • INSERT: Add new data into a table.
    • UPDATE: Modify existing data.
    • DELETE: Remove data from a table.

Step 3: What are Triggers in SQL

  • Definition: A trigger is a special type of stored procedure that automatically executes in response to certain events on a particular table or view.

Types of Triggers

  • BEFORE Trigger: Executes before an insert, update, or delete operation.
  • AFTER Trigger: Executes after an insert, update, or delete operation.

Common Use Cases

  • Automatically updating a log table when data changes.
  • Enforcing business rules at the database level.

Step 4: Creating a Trigger

Syntax for Creating a Trigger

CREATE TRIGGER trigger_name
BEFORE|AFTER INSERT|UPDATE|DELETE ON table_name
FOR EACH ROW
BEGIN
  -- SQL statements
END;

Example of a Trigger

  1. Create a trigger that logs changes:
    CREATE TRIGGER log_changes
    AFTER UPDATE ON employees
    FOR EACH ROW
    BEGIN
      INSERT INTO employee_log (employee_id, changed_at)
      VALUES (OLD.id, NOW());
    END;
    

Step 5: Managing Triggers

  • Viewing Triggers: You can view existing triggers using the following SQL command:
    SHOW TRIGGERS;
    
  • Dropping a Trigger: If you need to remove a trigger, use:
    DROP TRIGGER trigger_name;
    

Conclusion

In this tutorial, we explored the fundamentals of Database Management Systems and Relational Database Management Systems, focusing on SQL and the application of triggers. Understanding these concepts is crucial for effective database management and automation of tasks within a database environment. As a next step, consider practicing the creation and management of triggers in a SQL environment to solidify your knowledge.