I would be doing this in a new user and so first you need to have the administrative priviledges to create new user. By default the Scott user does not have the priviledges and you need to login using the System user.
Create New User In Oracle
grant him necessary priviledges
<tablespace> is normally 'SYSTEM'
Now create the tables
Now create the trigger
Update Trigger
Delete Trigger
Create New User In Oracle
Code: SQL
CREATE User <UserName> IDENTIFIED BY ;
Code: SQL
GRANT CREATE session TO <username>;
GRANT CREATE TABLE TO <username>;
GRANT CREATE TRIGGER TO <username>;
ALTER USER <username> QUOTA UNLIMITED ON
Now create the tables
Code: SQL
CREATE TABLE Details (
RegNo varchar (50) NOT NULL ,
RegYear varchar (4) NOT NULL ,
FullName varchar (50) NOT NULL ,
FathersName varchar (50) NOT NULL ,
Location varchar (250) NOT NULL ,
Village varchar (250) NOT NULL ,
PresentAdd varchar (500) NOT NULL ,
CreatedBy varchar (50) NOT NULL ,
DateCreated date NOT NULL ,
UpdatedBy varchar (50) NULL ,
DateUpdated date NULL,
PRIMARY KEY (RegNo,RegYear)
);
CREATE TABLE LogDetails (
LogType varchar (50) NULL ,
RegNo varchar (50) NOT NULL ,
RegYear varchar (4) NOT NULL ,
FullName varchar (50) NOT NULL ,
FathersName varchar (50) NOT NULL ,
Location varchar (250) NOT NULL ,
Village varchar (250) NOT NULL ,
PresentAdd varchar (500) NOT NULL ,
CreatedBy varchar (50) NOT NULL ,
DateCreated date NOT NULL ,
UpdatedBy varchar (50) NULL ,
DateUpdated date NULL
);
Update Trigger
Code: SQL
CREATE OR REPLACE TRIGGER AuditTrailUpdate
AFTER UPDATE ON Details
REFERENCING OLD AS myRow
FOR EACH ROW
INSERT INTO LogDetails(
LogType,
RegNo,
RegYear,
FullName,
FathersName,
Location,
Village,
PresentAdd,
CreatedBy,
DateCreated,
UpdatedBy,
DateUpdated
)
VALUES(
'updated',
:myRow.RegNo,
:myRow.RegYear,
:myRow.FullName,
:myRow.FathersName,
:myRow.Location,
:myRow.Village,
:myRow.PresentAdd,
:myRow.CreatedBy,
:myRow.DateCreated,
:myRow.UpdatedBy,
:myRow.DateUpdated
)
/
Code: SQL
CREATE OR REPLACE TRIGGER AuditTrailDelete
AFTER DELETE ON Details
REFERENCING OLD AS myRow
FOR EACH ROW
INSERT INTO LogDetails(
LogType,
RegNo,
RegYear,
FullName,
FathersName,
Location,
Village,
PresentAdd,
CreatedBy,
DateCreated,
UpdatedBy,
DateUpdated
)
VALUES(
'deleted',
:myRow.RegNo,
:myRow.RegYear,
:myRow.FullName,
:myRow.FathersName,
:myRow.Location,
:myRow.Village,
:myRow.PresentAdd,
:myRow.CreatedBy,
:myRow.DateCreated,
:myRow.UpdatedBy,
:myRow.DateUpdated
)
/


