PL SQL Triggers || Triggers in PL/SQL || PL/SQL Tutorial for Beginners in Hindi

Опубликовано: 04 Ноябрь 2024
на канале: Coding Glitz
31,350
588

A trigger is a named PL/SQL block stored in the Oracle Database and executed automatically when a triggering event takes place.

Create Audit Table where we will be logging the transaction details:

create table audits
(auditid number generated by default as identity primary key,
tableName varchar2(200),
transactionName varchar2(10),
userName varchar2(30),
transactionDate Date);

Use any table created by you in place of Customers in the below trigger.

CREATE OR REPLACE TRIGGER customersAuditTRG
AFTER
UPDATE OR DELETE
ON customers
FOR EACH ROW
DECLARE
transaction VARCHAR2(10);
BEGIN
-- determine the transaction type
transaction := CASE
WHEN UPDATING THEN 'UPDATE'
WHEN DELETING THEN 'DELETE'
END;
-- insert a row into the audit table
INSERT INTO audits (tableName, transactionName, userName, transactionDate)
VALUES('CUSTOMERS', transaction, USER, SYSDATE);
END;
/


Please like & share the video.

Subscribe the Channel to keep watching interesting videos helpful for your career growth:

   / @codingglitz  

--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------

Checkout different playlists:

PLSQL Tutorial :    • PLSQL Tutorial || PL SQL tutorial for...  
Learn DBMS & SQL :    • SQL Tutorial for Beginners || SQL Pla...  
SQL Interview Questions and answers:    • sql interview questions and answers i...  
Java Interview Questions and Answers :    • JAVA Programs for interview  
IT Career guidance:    • Career Guidance  
Interview Tips :    • Interview Tips  
IT Essentials and Tricks :    • IT Essentials and Tricks  

--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------

Checkout Important videos :

Top 30 SQL Queries Interview Questions and Answers :    • SQL Queries Interview Questions and a...  
Top 50 SQL Concepts Interview Questions and Answers :    • SQL Interview Questions And Answers  
Employee earning maximum salary in each department query :    • SQL Query to find Employee with maxim...  
How to delete duplicate rows from any table (2 different solutions):    • SQL query to delete duplicate rows in...  
How to find Nth highest salary (3 different solutions):    • SQL query to find Nth Highest salary ...  
Tricky SQL Queries Part1 :    • SQL Tricky and Important Interview Qu...  
Basics of Database :    • What is DBMS?  Learn Basics of DBMS |...  
SQL OPERATORS :    • Operators in SQL  || SQL Tutorial for...  
AGGREGATE FUNCTION:    • Aggregate function  || SQL Tutorial f...  
GROUP BY :    • GROUP BY  & HAVING || SQL Tutorial fo...  
Solve any Date related query :    • How to Solve any SQL Query related to...  
How to use Substring :    • Substrings in SQL  | Learn SQL | SQL ...  

How to practice SQL Queries in local / Install Database in local :    • How to Install Oracle Database (19C) ...  
IT Jobs without Coding :    • IT Jobs without coding with high sala...  


--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------