0% found this document useful (0 votes)
181 views27 pages

DBMS Library and Student Database Tasks

The document outlines the creation of a database for a university library and student management system, detailing the structure and relationships of tables such as LibraryBooks, IssuedBooks, PersonalInfo, PaperDetails, and AcademicDetails. It includes SQL commands for creating tables, inserting records, and performing various queries to manage and retrieve data. Additionally, it describes operations like updating, deleting records, and listing specific information based on conditions.

Uploaded by

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

DBMS Library and Student Database Tasks

The document outlines the creation of a database for a university library and student management system, detailing the structure and relationships of tables such as LibraryBooks, IssuedBooks, PersonalInfo, PaperDetails, and AcademicDetails. It includes SQL commands for creating tables, inserting records, and performing various queries to manage and retrieve data. Additionally, it describes operations like updating, deleting records, and listing specific information based on conditions.

Uploaded by

shanmukhk05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Create a database having two tables with the specified fields, to computerise a library
system of a University College.
LibraryBooks (Accession number, Title, Author, Department, PurchaseDate, Price),
IssuedBooks (Accession number, Borrower)
a) Identify primary and foreign keys. Create the tables and insert at least
5 records in each table.
b) Delete the record of a book titled “Database System Concepts”.
c) Change the Department of the book titled “Discrete Maths” to “CS”.
d) List all books that belong to “CS” department.
e) List all books that belong to “CS” department and are written by author
“Navathe”.
f) List all computers (Department=”CS”) that have been issued.
g) List all books which have a price less than 500 or purchased between
“01/01/1999” and “01/01/2004”.
Answer:
a.​ Identify primary and foreign keys. Create the tables and insert at least
5 records in each table.
Primary Key:Accession Number in LibraryBooks table.
Foreign Key: Accession Number in IssuedBooks table.

❖​ Creating the tables1 LibraryBooks:


create table LibraryBooks(AccNo int primary key,Title varchar2(20),Author
varchar2(10),Department varchar2(10),Purchasedate date,Price int);
❖​ Output:
Table created.
❖​ Describe the table:It displays the structure of the table:
desc LibraryBooks;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into LibraryBooks
values(103867,'DatabaseSystem','Ayesha','CS','01-july-1996',950);
❖​ Output:
1 row(s) inserted.
2.​ insert into LibraryBooks
values(125769,'CostAccounting','Navathe','MBA','17-may-2001',490);
❖​ Output:
1 row(s) inserted.
3.​ insert into LibraryBooks
values(158379,'DiscreteMaths','Fatima','ME','16-jul-2002',870);
❖​ Output:
1 row(s) inserted.

❖​ Selecting all the records:


select * from LibraryBooks;
❖​ Output:

❖​ Creating table 2: IssuedBooks


create table IssuedBooks(AccNo int references LibraryBooks(AccNo),Borrower
varchar2(10),primary key(AccNo));
❖​ Output:
Table created.
❖​ Describe the table:It displays the structure of the table:
desc IssuedBooks;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into IssuedBooks values(158379,'Nithisha');
❖​ Output:
1 row(s) inserted.
2.​ insert into IssuedBooks values(103867,'Saisree');
❖​ Output:
1 row(s) inserted.
3.​ insert into IssuedBooks values(510965,'Saiprabha');
❖​ Output:
1 row(s) inserted.

❖​ Selecting all the records:


select * from IssuedBooks;
❖​ Output:

b. Delete the record of book title “DatabaseSystem”


Answer:
delete from LibraryBooks where title='DatabaseSystem';

delete from IssuedBooks where Accno=103867;


❖​ Output:
1 row(s) deleted.

delete from LibraryBooks where title='DatabaseSystem';


❖​ Output:
1 row(s) deleted.

Check whether row is deleted or not by the following query


select * from LibraryBooks;
❖​ Output:

c. Change the department of the book titled “Discretemaths” to “CS”


Answer:
update LibraryBooks set Department='CS' where Title='DiscreteMaths';
❖​ Output:
1 row(s) updated.
Check whether row is updated or not by the following query
select * from LibraryBooks;
❖​ Output:
d. List all books that belong to “CS’ department.
Answer:
select Title from LibraryBooks where Department='CS';
❖​ Output:

[Link] all books that belongs to “CS’ department and are written by author “Navathe”.
Answer:
select Title from LibraryBooks where Department='CS' and Author='Navathe';
❖​ Output:

f. List all computers (Department=”CS”) that have been issued.


Answer:
select [Link],[Link],[Link] from LibraryBooks l,IssuedBooks i where
[Link]='CS' and [Link]=[Link];
❖​ Output:

g. List all books which have a price less than 500 or purchased between “01/01/1999”
and “01/01/2004”.
Answer:
select Title from LibraryBooks where Price<500 or (PurchaseDate between '01-jan-1999' and
'01-jan-2004');
❖​ Output:
2. Create a database having three tables to store the details of students of the Computer
Department in your college.
Personal information about Student (College roll number, Name of student, Date of
birth, Address, Marks(rounded off to whole number) in percentage at 10 + 2, Phone number)
Paper Details (Paper code, Name of the Paper)
Student’s Academic and Attendance details (College roll number, Paper
Code, Attendance, Marks in home examination).
a) Identify primary and foreign keys. Create the tables and insert at least 5 records in
each table.
b) Design a query that will return the records (from the second table) along with the
name of the student from the first table, related to students who have more than 75%
attendance and more than 60% marks in paper2.
c) List all students who live in “Delhi” and have marks greater than 60 in paper1.
d) Find the total attendance and total marks obtained by each student.
e) List the name of the student who has got the highest marks in paper2.
Answer:
a.​ Identify primary and foreign keys. Create the tables and insert at least
5 records in each table.
Primary Key:College roll number in Personal information about Student ‘table’.
Paper code in Paper details table.
Foreign Key: College roll number, Paper code in student’s Academic and Attendance
details table
❖​ Creating the tables1 PersonalInfo:
create table PersonalInfo(RollNo int primary key,Name varchar2(6),DOB
date,Address varchar2(6),Marks int,PhoneNo int);
❖​ Output:
Table created.
❖​ Describe the table structure:
desc PersonalInfo;
❖​ Output:
❖​
insert at least 5 records in each table.
1.​ insert into PersonalInfo values(101,'Ayesha','28-may-1992','Hyd',89,8976543210);
Output:
1 row(s) inserted.
2.​ insert into PersonalInfo values(102,'Rabia','26-july-1991','Ranchi',72,8436173378);
Output:
1 row(s) inserted.
3.​ insert into PersonalInfo values(103,'Ameer','15-apr-1989','Goa',69,8199765347);
Output:
1 row(s) inserted.
4.​ insert into PersonalInfo values(104,'Narmad','12-may-1991','Delhi',69,7314256772);
Output:
1 row(s) inserted.
5.​ insert into PersonalInfo values(105,'Anusha','04-oct-1996','Delhi',80,7896543210);
Output:
1 row(s) inserted.
❖​ Selecting all the records:
select * from PersonalInfo;
❖​ Output:

❖​ Creating the tables2 PaperDetails:


create table PaperDetails(Papercode varchar2(10)primary key,PaperName varchar2(10));
❖​ Output:
Table created.
❖​ Describe the table structure:
desc PaperDetails;
❖​ Output:
❖​ insert at least 5 records in each table.
1.​ insert into PaperDetails values('Paper1','JP');
❖​ Output:
1 row(s) inserted.
2.​ insert into PaperDetails values('Paper2','CPP');
❖​ Output:
1 row(s) inserted.

3.​ insert into PaperDetails values('Paper3','C');


❖​ Output:
1 row(s) inserted.
4.​ insert into PaperDetails values('Paper4','DS');
❖​ Output:
1 row(s) inserted.
5.​ insert into PaperDetails values('Paper5','Python');
❖​ Output:
1 row(s) inserted.
❖​ Selecting all the records:
select * from PaperDetails;
❖​ Output:

❖​ Creating the tables3 AcademicDetails:


create table AcademicDetails(RollNo int references PersonalInfo(RollNo),Papercode
varchar2(10)references PaperDetails(Papercode),Attendance int,Marksathome int,primary
key(RollNo,Papercode));
❖​ Output:
Table created.
❖​ Describe the table structure:
desc AcademicDetails;
❖​ Output:
❖​ insert at least 5 records in each table.
1.​ insert into AcademicDetails values(101,'Paper1',80,98);
❖​ Output:
1 row(s) inserted.
2.​ insert into AcademicDetails values(102,'Paper2',70,27);
❖​ Output:
1 row(s) inserted.

3.​ insert into AcademicDetails values(103,'Paper3',60,96);


❖​ Output:
1 row(s) inserted.
4.​ insert into AcademicDetails values(104,'Paper4',65,80);
❖​ Output:
1 row(s) inserted.
5.​ insert into AcademicDetails values(105,'Paper1',75,81);
❖​ Output:
1 row(s) inserted.
❖​ Selecting all the records:
select * from AcademicDetails;
❖​ Output:

b. Design a query that will return the records (from the second table) along with the
name of the student from the first table, related to students who have more than or
equal to 70% attendance and more than 60% marks in paper2.
Answer:select [Link],[Link],[Link] from PaperDetails pd,PersonalInfo
p,AcademicDetails a where [Link]>=70 and [Link]=[Link] and
[Link]=[Link] and [Link]='Paper2' and [Link]>60;
❖​ Output:
c. List all students who live in “Delhi” and have marks greater than 60 in paper1.
❖​ Answer:select [Link],[Link],[Link],[Link],[Link] from PaperDetails
pd,PersonalInfo p,AcademicDetails a where [Link]=[Link] and
[Link]=[Link] and [Link]='Paper1' and [Link]>60 and
[Link]='Delhi';
❖​ Output:

d. Find the total attendance and total marks obtained by each student.
❖​ Answer:
select [Link],sum([Link]),sum([Link]) from PaperDetails pd,PersonalInfo
p,AcademicDetails a where [Link]=[Link] and [Link]=[Link] group by
[Link];
❖​ Output:

e. List the name of the student who has got the highest marks in paper2.
Answer:select [Link] from PersonalInfo p,AcademicDetails a where [Link]=[Link]
and [Link]='Paper2' group by [Link] having sum([Link])>=all(select sum([Link])
from PersonalInfo p,AcademicDetails a where [Link] =[Link] and [Link]='Paper2'
group by Name);
❖​ Output:

3. Create the following tables and answer the queries given below:
​ Customer(CustId,Email,Name,Phone,ReferrerId)
​ Bicycle(BicycleId,Datepurchased,Color,CustId,ModelNo)
​ Service(StartDate,BicycleId,EndDate)
a.​ Identify primary and foreign [Link] the tables and insert at least 5 records
in each table.
b.​ List all the customers who have the bicycles manufactured by manufacturer
“Honda”.
c.​ List the bicycles purchased by the customers who have been referred by
customer “C1”.
d.​ List the manufacture of red colored bicycles.
e.​ List the models of the bicycles given for service.

a.​ Identify primary and foreign [Link] the tables and insert at least 5 records
in each table.
​ Answer:
​ Primary Keys: CustId in Customer table
​ ​ ​ BicycleId in Bicycle table
​ ​ ​ ModelNo in BicycleModel table
​ Foreign Keys: CustId,ModelNo in Bicycle table
​ ​ ​ BicycleId in Service table.

❖​ Creating the tables1 Customer


create table Customer(CustId varchar2(2),Email varchar2(20),Name varchar2(8),Phone
int,ReferredId varchar2(2),constraint pk1 primary key(CustId));
❖​ Output:
Table created.
❖​ Describe the table structure:
desc Customer;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into Customer values('C1','shoeb@[Link]','Sheed',9876543210,'R1');
❖​ Output:
1 row(s) inserted.
2.​ insert into Customer values('C2','zuberi@[Link]','Zuberi',9642113561,'R2');
❖​ Output:
1 row(s) inserted.
3.​ insert into Customer values('C3','vara@[Link]','Vara',8374219652,'R3');
❖​ Output:
1 row(s) inserted.
4.​ insert into Customer values('C4','venky@[Link]','Venky',8967254160,'R4');
❖​ Output:
1 row(s) inserted.
5.​ insert into Customer values('C5','adil@[Link]','Adil',8275139621,'R5');
❖​ Output:
1 row(s) inserted.
❖​ Selecting all the records:
select * from Customer;
❖​ Output:

❖​ Creating the tables2 BicycleModel


create table BicycleModel(ModelNo varchar2(2),Manufacturer varchar2(7),Style
varchar2(8),constraint pk2 primary key(ModelNo));
❖​ Output:
Table created.
❖​ Describe the table structure:
desc Customer;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into BicycleModel values('M1','Honda','CB');
❖​ Output:
Table created.
2.​ insert into BicycleModel values('M2','Yamaha','FZ25');
❖​ Output:
Table created.
3.​ insert into BicycleModel values('M3','Honda','CBR');
❖​ Output:
Table created.
4.​ insert into BicycleModel values('M4','Yamaha','Fascino');
❖​ Output:
Table created.
5.​ insert into BicycleModel values('M5','Hero','Splender');
❖​ Output:
Table created.
❖​ Selecting all the records:
select * from BicycleModel;
❖​ Output:

❖​ Creating the tables3 Bicycle


create table Bicycle(BicycleId varchar2(2),DatePurchased date,Color varchar2(6),CustId
varchar2(2),ModelNo varchar2(2),constraint pk3 primary key(BicycleId),constraint fk1
foreign key(CustId)references Customer,constraint fk2 foreign key(ModelNo)references
BicycleModel);
❖​ Output:
Table created.
❖​ Describe the table structure:
desc Bicycle;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into Bicycle values('B1','02-jul-2017','Black','C1','M1');
❖​ Output:
1 row(s) inserted.
2.​ insert into Bicycle values('B2','01-june-1996','Red','C2','M2');
❖​ Output:
1 row(s) inserted.
3.​ insert into Bicycle values('B3','05-nov-2001','Grey','C3','M3');
❖​ Output:
1 row(s) inserted.
4.​ insert into Bicycle values('B4','04-aug-2015','Black','C4','M4');
❖​ Output:
1 row(s) inserted.
5.​ insert into Bicycle values('B5','04-june-2018','Red','C5','M5');
❖​ Output:
1 row(s) inserted.
❖​ Selecting all the records:
select * from Bicycle;
❖​ Output:

❖​ Creating the tables4 Service


create table Services(StartDate date,BicycleId varchar2(2),EndDate date,constraint pk4
primary key(BicycleId,StartDate),constraint fk3 foreign key(BicycleId)references Bicycle);
❖​ Output:
Table created.
❖​ Describe the table structure:
desc Services;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into Services values('11-jul-2017','B1','13-oct-2017');
❖​ Output:
1 row(s) inserted.
2.​ insert into Services values('10-sep-1996','B2','12-sep-1996');
❖​ Output:
1 row(s) inserted.
3.​ insert into Services values('07-mar-2002','B3','09-mar-2002');
❖​ Output:
1 row(s) inserted.
4.​ insert into Services values('08-nov-2015','B4','10-nov-2015');
❖​ Output:
1 row(s) inserted
5.​ insert into Services values('22-aug-2018','B5','24-aug-2018');
❖​ Output:
1 row(s) inserted
❖​ Selecting all the records:
select * from Services;
❖​ Output:

b. List all the customers who have the bicycles manufactured by manufacturer
“Honda”.
Answer:
select [Link],[Link],[Link],[Link],[Link] from Customer c,Bicycle
b,BicycleModel m where [Link]=[Link] and [Link]=[Link] and
[Link]='Honda';
❖​ Output:

c. List the bicycles purchased by the customers who have been referred by customer
“C1”.
Answer:
select * from Bicycle b,Customer c where [Link]=[Link] and [Link]='C1';
❖​ Output:

d. List the manufacture of red colored bicycles.


Answer:
select [Link] from BicycleModel m,Bicycle b where [Link]=[Link] and
[Link]='Red';
❖​ Output:
[Link] the models of the bicycles given for service.
Answer:
select [Link] from BicycleModel m,Services s,Bicycle b where
[Link]=[Link] and [Link]=[Link];
❖​ Output:

4. Create the following tables,enter at least 5 records in each table and answer the
queries given below.
Employee(Person_Name,Street,City)
Works(Person_Name,Company_Name,Salary)
Company(Company_Name,City)
Manages(Person_Name,Manager_Name)
a.​ Identify primary and foreign keys.
b.​ Alter table employee ,add a column “email” of type varchar2(20).
c.​ Find the name of all managers who work for both Samba Bank and NCB Bank.
d.​ Find the names,street address,cities of residence and salary of all employees who
work for “Samba Bank” and earn more than 10,000.
e.​ Find the names of all employees who live in the same city as the company for
which they work.
f.​ Find the highest salary,lowest salary and average salary paid by each company.
g.​ Find the sum of salary and number of employees in each company.
h.​ Find the name of the company that pays the highest salary.

Answers:
a.​ Identify primary and foreign keys.
❖​ Primary Keys:
Person_Name in Employee table.
Company_Name in Works table.
❖​ Foreign Keys:
​ Person_Name in works table.
Company_Name in Company table.
Person_Name in Manages table.

❖​ Creating the tables1 Employee


create table Employee(Person_Name varchar2(10)primary key,Street varchar2(10),City
varchar2(10));
❖​ Output:
Table created.

❖​ Describe the table structure:


desc Employee;
❖​ Output:

❖​ Insert at least 5 records in each table.


[Link] into Employee values('Ravi','Charminar','Hyderabad');
❖​ Output:
1 row(s) inserted.
2. insert into Employee values('Rajesh','Benzcircle','Vijayawada');
❖​ Output:
1 row(s) inserted.
3. insert into Employee values('Ramesh','Beachroad','Vizag');
❖​ Output:
1 row(s) inserted.

❖​ Selecting all the records:


select * from Employee;
❖​ Output:

❖​ Creating the tables2 Works


create table Works(Person_Name varchar2(10)references
Employee(Person_Name),Company_Name varchar2(10),Salary int,primary
key(Person_Name));
❖​ Output:
Table created.
❖​ Describe the table structure:
desc Works;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into Works values('Ravi','Samba-Bank',31000);
❖​ Output:
1 row(s) inserted.
2.​ insert into Works values('Rajesh','NCB-Bank',28000);
❖​ Output:
1 row(s) inserted.
3.​ insert into Works values('Ramesh','State_Bank',30000);
❖​ Output:
1 row(s) inserted.

❖​ Selecting all the records:


select * from Works;
❖​ Output:

❖​ Creating the tables3 Company


create table Company(Company_Name varchar2(10)primary key,City varchar2(10));
❖​ Output:
Table created.
❖​ Describe the table structure:
desc Company;
❖​ Output:

❖​ Insert at least 5 records in each table.


1.​ insert into Company values('Samba-Bank','Hyderabad');
❖​ Output:
1 row(s) inserted.
2.​ insert into Company values('NCB-Bank','Vijayawada');
❖​ Output:
1 row(s) inserted.
3.​ insert into Company values('State_Bank','Vizag');
❖​ Output:
1 row(s) inserted.

❖​ Selecting all the records:


select * from Company;
❖​ Output:

❖​ Creating the tables4 Manages


create table Manages(Person_Name varchar2(10)references
Employee(Person_Name),Manager_Name varchar2(10),primary key(Person_Name));
❖​ Output:
Table created.

❖​ Describe the table structure:


desc Manages;
❖​ Output:
❖​ Insert at least 5 records in each table.
1.​ insert into Manages values('Ravi','Nithisha');
❖​ Output: 1 row(s) inserted.
2.​ insert into Manages values('Rajesh','Nithisha');
❖​ Output: 1 row(s) inserted.
3.​ insert into Manages values('Ramesh','Saisree');
❖​ Output: 1 row(s) inserted.

❖​ Selecting all the records:


select * from Manages;
❖​ Output:

b. Alter table employee,add a column “email” of type varchar2(20);


Answer:
alter table Employee add Email varchar2(20);
❖​ Output:
Table altered.
desc Employee;

c. Find the name of all managers who work for both Samba Bank and NCB Bank.
Answer:
select distinct(m.Manager_Name)from Manages m,Works w where
w.Person_Name=m.Person_Name and (w.Company_Name='Samba-Bank' or
w.Company_Name='NCB-Bank');
❖​ Output:
d. Find the names,street address,cities of residence and salary of all employees who
work for “Samba Bank” and earn more than 10000.
Answer:
select Employee.Person_Name,[Link],[Link] from Employee,Works
where Employee.Person_Name=Works.Person_Name and Company_Name='Samba-Bank'
and Salary>10000;
❖​ Output:

e. Find the names of all employees who live in the same city as the company for which
they work.
Answer:
select e.Person_Name from Employee e,Works w,Company c where
e.Person_Name=w.Person_Name and [Link]=[Link] and
w.Company_Name=c.Company_Name;
❖​ Output:

f. Find the highest salary,lower salary and average salary paid by each company.
Answer:
select Company_Name,max(Salary),min(Salary),avg(Salary) from Works group by
Company_Name;
❖​ Output:
g. Find the sum of salary and number of employees in each company.
Answer:
select Company_Name,sum(Salary),count(Person_Name) from Works group by
Company_Name;
❖​ Output:

h. Find the name of the company that pays the highest salary.
Answer:
select Company_Name from Works group by Company_Name having
sum(Salary)>=all(select sum(Salary) from Works group by Company_Name);
❖​ Output:

6. Write a PL/SQL Program to demonstrate Procedure.


declare
a number;
b number;
c number;
procedure findmin(x in number,y in number,z out number)is
begin
if x<y then
z:=x;
else
z:=y;
end if;
end;
begin
a:=23;
b:=45;
findMin(a,b,c);
dbms_output.put_line('Minimum of(23,45)='||c);
End;
❖​ Output:
Minimum of(23,45)=23
Statement processed.

7. Write a PL/SQL Program to demonstrate Function.


declare
a number;
b number;
c number;
function findmin(x in number,y in number)
return number
is z number;
begin
if x<y then
z:=x;
else
z:=y;
end if;
return z;
end;
begin
a:=23;
b:=45;
c:=findMin(a,b);
dbms_output.put_line('Minimum of(23,45)='||c);
end;
❖​ Output:
Minimum of(23,45)=23
Statement processed.
8. Write a PL/SQL program to Handle Exceptions.
declare
x number:=10;
y number:=0;
z number;
begin
z:=x/y;
​ dbms_output.put_line('The value of z is:'||z);
exception
when zero_divide then
dbms_output.put_line('Error:Attempt to divide by zero');
end;
❖​ Output:
Error:Attempt to divide by zero
Statement processed.
9. Write a PL/SQL Program to perform a set of DML Operations.
DECLARE
​ ​ v_count NUMBER;
BEGIN
INSERT INTO employees (Eid, First_name, Last_name, Hired_date, Salary)
VALUES (101, 'Doe', 'John', '02-FEB-2022', 60000);
​ ​ UPDATE employees SET Salary = 55000 WHERE Eid = 101;
​ ​ DELETE FROM employees WHERE Eid = 102;
​ ​ SELECT COUNT(*) INTO v_count FROM employees;
​ ​ DBMS_OUTPUT.PUT_LINE('Total number of employees: ' || v_count);
END;

Note:To execute the above program First create the table employees with the above
mentioned attributes.
Insert the two to three rows in the table.
Then execute the program you will output.

10. Create a View using PL/SQL program.

EID ENAME DNAME SALARY


101 Nikhil CS 50000
102 Vinay ME 45000
103 Rethu Ele 30000
104 Lahari MBA 56000
105 Ramu MCA 60000
106 Rahul BCOM 66000

CREATE VIEW EMPLOYEE3210 AS SELECT EID, ENAME, DNAME FROM


EMPLOYEE123 ORDER BY ENAME;

❖​ OUT PUT:
VIEW CREATED

SELECT * FROM EMPLOYEE3210;


EID ENAME DNAME
104 Lahari MBA
101 Nikhil CS
106 Rahul BCOM
105 Ramu MCA
103 Rethu Ele
102 Vinay ME

11. Write a PL/SQL Program on Statement Level Trigger.


CREATE OR REPLACE TRIGGER after_insert_employees
AFTER INSERT ON Employee
DECLARE
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count FROM Employee;
DBMS_OUTPUT.PUT_LINE('Total number of rows after insert: ' || v_count);
END;
❖​ Output:
Trigger created

❖​ INSERT INTO Employee VALUES (2, 'Jane', 'Smith', '10-sep-2024',50000);

Total number of rows after insert: 3

1 row(s) inserted.

12. Program to demonstrate on Row Level Trigger.


CREATE OR REPLACE TRIGGER prevent_update_trigger
BEFORE UPDATE ON Employee
FOR EACH ROW
BEGIN
RAISE_APPLICATION_ERROR(-20001, 'Updates are not allowed on this table.');
END;
/
.

You might also like