Wednesday 27 July 2016

Trigger Example in Oracle

As Salamo alaikum wa rahmatullah


--Create Table Name T

Create Table T
(
    ID number(10) primary key,
    FName varchar2(25) not null,
    Lname varchar2(25) not null
)

 --Create Table Name T_Audit 

Create Table T_Audit
(
    ID number(10) primary key,
    FName varchar2(25) not null,
    Lname varchar2(25) not null,
    Created_dt Date
)

-- Create Trigger 

Create Or Replace Trigger Trg_Test
Before INSERT ON T
For Each Row
Begin
    Insert into T_Audit (ID,Fname,Lname,Created_dt) values(:new.ID,:new.Fname,:new.Lname,sysdate);
End;

Insert into T Values (1,'Zaheer','Khan')
Insert into T Values (2,'Mohammad','Sami')
Insert into T Values (3,'Iqbal','Abdullah')

commit;

Select * from T


Select * from T_Audit

--
Ma Asalaam
Passion 4 Oracle

No comments:

Post a Comment