0% found this document useful (0 votes)
18 views4 pages

PL SQL Trigger

Uploaded by

saketh bhargava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

PL SQL Trigger

Uploaded by

saketh bhargava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Exp.No:20 iggers [Triggers are stored programs, which are automatically executed or fired when some vent occurs. Triggers are written to be executed in response to any of the following vents. A database manipulation (DML) statement (DELETE, INSERT, or UPDATE). © A database definition (DDL) statement (CREATE, ALTER, or DROP). © A. database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, orSHUTDOWN), [Triggers could be defined on the table, view, schema, or database with which the event associated. Advantages of Triggers ‘These are the following advantages of Triggers: Trigger generates some derived column values automatically © Enforces referential integrity © Event logging and storing information on table access Auditing © Synchronous replication of tables © Imposing security authorizations © Preventing invalid transactions 66 PLSQL CODE: SQL> create table product 2 (ld numberi5), 3. Name varchar2(10), 4 Price number(7)); Table created SQL> create table p_price 2 (Id number(5), 3. Name varchar2(10), 4 Price number(7)); Table created SQL> insert into product values(1, TV’, 50000); SQL> insert into product values(2, ‘CYCLE, 5000); SQL> select * from product; ID NAME PRIC 1Tv 21000 2CYCLE 5000 Trigger Update SQL> create or replace trigger TI before update of price on product 2 for each row 3 begin 4 insert into p_price values(-old.ld,:old.Name,:old Price); 5 end; 6! Trigger created 67 OUTPUT Trigger created SQL> update product set price-20000 where Id~15 1 row updated. SQL> select * from p_price; ID NAME PRICE aw SQL> SELECT * FROM PRODUCT; ID NAME PRICE 1 2 CYCLE ‘5280 Trigger Delete: SQL> create or replace trigger T1 before delete on product for each row begin insert into p_price values(:old.td,:old. Name,:old.Price); end; f Trigger ereated. OUTPUT 68 Trigger created. i SQL> delete product where i 1 row deleted SQL> select * from product; ID NAME PRICE aw 21000 SQI> select ™ from p_price: ID NANC PRICE 2 CYCLE 3000 69

You might also like