Professional Documents
Culture Documents
Ilovepdf Merged
Ilovepdf Merged
DATE :
AIM:
To Creation of a database and writing SQL queries to retrieve information from the
database.
1
(iii) Write a SQL query to change the details
ALTER TABLE Student RENAME COLUMN Address TO Details;
(iv) Write a SQL query adding a phone number in the existing table
ALTER TABLE Student ADD Phone varchar(255);
(v) Write a SQL query to change PID data type (int, varchar)
ALTER TABLE Student
ADD CONSTRAINT STUDENTID PRIMARY KEY (STUDENTID);
2
(vi) Write a SQL query to update constraints
ALTER TABLE Student
MODIFY Phone int;
(vii) Write a SQL query to set a range for 10 digits exactly for phone number
ALTER TABLE student
ADD CONSTRAINT check_ten_digits
CHECK (LENGTH(phone) = 10 AND phone NOT LIKE '%[^0-9]%');
RESULT:
Hence Data Definition language commands in structured query language are
performed and output verified.
3
EX NO : 02 WORKING WITH DATA MANIPULATION COMMANDS
* Performing Insertion, Deletion, Modifying, Altering, Updating and Viewing records based on conditions.
DATE :
AIM:
To Creation of a database and writing SQL queries to retrieve information from the
database.
(i) INSERT:
Purpose:
To add records to the table
Syntax:
i. Direct method - only one record can be inserted in the field at a time
➢ Insert into <table name> values <values for all columns>
ii. Null method - we can skip some fields
➢ Insert into <table name> (column name) values (values for columns)
iii. Macro method - More than one value can be inserted in the field at a time
➢ Insert into <table name> values <&column names>
(ii) SELECT:
Purpose:
To retrieve or view records within the table
Syntax:
➢ Select * from <table name>
➢ Select * from <table name> where (condition)
➢ Select (column name) from <table name>
(iii) UPDATE:
Purpose:
To modify records within the table
Syntax:
➢ Update <table name> set (column name) = (value)
➢ Update <table name> set (column name) = (value) where (condition)
(iv) DELETE:
Purpose:
To modify records from a table
Syntax:
➢ Delete from <table name>
➢ Delete from <table name> where (condition)
4
EXAMPLE QUERIES:
5
(iv) Write a SQL query to Performing Altering
ALTER TABLE Students
ADD Email varchar(255);
RESULT:
Hence Data manipulation commands (INSERT, DELETE, UPDATE, ALTER,
SELECT) in structured query language are performed and output verified.
6
EX NO : 03 CONSTRUCT A ER MODEL FOR THE APPLICATION TO BE
CONSTRUCTED TO A DATABASE
DATE :
AIM:
The aim of this experiment is to design and construct an Entity-Relationship (ER)
model for an application that will be implemented in a database management system.
REQUIREMENTS:
❖ Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
❖ MySQL 5.6.1
PROCEDURE:
(i) Identifying Entities and Attributes:
➢ Analyze the application domain and identify relevant entities and their
attributes.
➢ Create a list of entities and their respective attributes based on the
requirements.
7
EXAMPLE:
Entities:
1. BUS
2. Ticket
3. Passenger
Relationships:
1. Reservation
2. Cancellation
E-R Model
Attributes of the following Entities
(i) BUS
❖ BusNo
❖ Source
❖ Destination
❖ CoachType
SCHEMA
Bus: Bus (BusNo: String, Source: String, Destination: String, CoachType: String)
8
(ii) TICKET
❖ TicketNo
❖ DOJ
❖ Address
❖ ContactNo
❖ BusNo
❖ SeatNo
❖ Source
❖ Destination
SCHEMA
Ticket(TicketNo: string, DOJ: date, Address:string,ContactNo: string, BusNo:String,
SeatNo:Integer,Source: String, Destination: String)
(iii) PASSENGER
❖ PassportID
❖ TicketNo
❖ Name
❖ ContactNo
❖ Age
❖ Sex
❖ Address
SCHEMA
Passenger(PassportID: String, TicketNo:string,Name: String, ContactNo:string,Age:
integer, Sex: character, Address: String)
9
(iv) RESERVATION
❖ PNRNo
❖ DOJ
❖ No_of_seats
❖ Address
❖ ContactNo
❖ BusNo
❖ SeatNo
SCHEMA
Reservation(PNRNo: String, DOJ: Date, NoofSeats: integer , Address: String,
ContactNo: String, , BusNo: String,SeatNo:Integer)
(v) CANCELLATION
❖ PNRNo
❖ DOJ
❖ SeatNo
❖ ContactNo
❖ Status
SCHEMA
Cancellation(PNRNo: String,DOJ: Date, SeatNo: integer,ContactNo: String,Status: String)
10
Concept design with E-R Model:
RESULT:
11
EX NO : 04 BASIC SQL FUNCTIONS
*single row, aggregate
DATE :
AIM:
To execute simple query using SQL Functions.
SQL FUNCTION:
❖ Set of instructions which will do some specific task
❖ It may or may not return the value
❖ It’s the module.
TYPES
(i) Single row function
1. Data function
2. Numeric function or arithmetic or mathematical Function
3. Character function
4. General function or Miscellaneous function
DATE FUNCTIONS
12
04. Write a query to find number of months between two dates.
SQL>SELECT MONTHS_BETWEEN (TO_DATE (’04-MAY-2001’,’DD-MON
YYYY’), TO_DATE (’14-FEB-2001’, ’DD-MON-YYYY’)) FROM DUAL;
MONTHS_BETWEEN (TO_DATE (’04-MAY-2001’, ’DD-MON-YYYY’),
TO_DATE(’14-FEB-2001’, ’DD-MON-YYYY’))
------------------------------------------------------------------------------------
2.6774194
05. Write a query to find the next day in a month of date specified
SQL>SELECT NEXT_DAY(SYSDATE,’SUNDAY’) FROM DUAL;
NEXT_DAY(
-----------------
18-FEB-01
09. Write a query to round off particular date to year preceding it.
SQL>SELECT TRUNC SYSDATE,’YEAR’) FROM DUAL;
TRUNC (SYS
---------------------
01-JAN-01
10. Write a query to round off particular date to month preceding it.
SQL>SELECT TRUNC SYSDATE,’MONTH’) FROM DUAL;
TRUNC (SYS
---------------------
01-FEB-01
13
11. Write a query to round off particular date to day preceding it.
SQL>SELECT TRUNC SYSDATE,’DAY’) FROM DUAL;
TRUNC (SYS
---------------------
11-FEB-01
RESULT:
Hence basic SQL functions were executed, database operations performed and output
verified.
14
EX NO : 05 SQL JOINS
* inner, outer & self-join
DATE :
AIM:
To know the use of join operators in SQL.
JOIN:
A join is used to combine rows from multiple tables. A join is performed whenever
two or more tables are listed in the form clause of an SQL statement.
TABLE STRUCTURE:
SQL>desc suppliers;
Name NULL? Type
------ --------- --------- -----------------
Supplier_id number(5)
Supplier_name varchar2(25)
SQL>desc order;
SUPPLIER:
Supid supname
------- ------ --------- ------
12 abi
13 chindu
14 nithi
15 selvi
ORDER:
Oid supid odate
------- ------- ---------- ------- --------- -------
111 12 1/9/09
222 23 8/9/09
333 14 6/9/09
444 25 3/9/09
555 15 17/9/09
15
NATURAL JOINS:
SQL>select * from supplier,ord where supplier.supid=ord.supid;
Supid supname Oid supid odate
-------- ---------- ----------- --------------- ------------- ---------- ------
12 abi 111 12 1/9/09
14 nithi 333 14 6/9/09
15 selvi 555 15 17/9/09
OUTER JOIN:
Left outer join:
SQL>select supplier.suPID ,supplier.suPNAME,ord.oDATE where supplier.su PID(+)=ord
.suPID;
16
EXAMPLE QUERIES :
(i) Create a db student with attributes & another database advisor with a set of attributes &
come up with a relationship table in which the db contains student name with corresponding
advisor.
SQL>Select * from student crossjoin advisor;
Stu
fname lname dob dues dept employ adv_no fname lname dob sal dept
no
122 ante rtie ni 20.05.27 25000 cse a900 00 122 john mart ieni 20.05.17 25000 cse
122 ante rtie ni 20.05.27 25000 cse a800 00 111 mark rain 15.06.11 35000 cse
122 ante rtie ni 20.05.27 25000 cse a700 00 333 mark rain 15.06.11 35000 cse
122 ante rtie ni 20.05.27 25000 cse 1 10 bond john 20.07.98 15000 eee
(ii) Create db employee with set of attributes similarly another db called parking lot with set
of attributes, where output should have employee name who use parking lot.
SQL>Selectname from employee park innerjoin parking on employee.park=parking;
FNAME
JOHN
MARK
bond
dejane
(iii) Display the name, city & birth month of the employees with following cosiderations:
a) employee address contains e_name, country & city details, e_id.
b) employee payroll contains e_id,e_dept, e_birthdate&doj.
17
(iv) List emp_id& gender for all married empls& include the names of any charity to which
the employee donate via the company program.
SQL>Selecteid,gender from employee innerjoin charity on employee.char = charity.char;
EID GENDER
RA01 Male
RA03 Female
RA05 Male
(v) Get employee name, project name, order by first name from employee detail & project
detail for those employee who have assigned project already.
ENAME PROJECT_NAME
Westbrook Machine Learning
Serena Biometrics
Wade Big data
(vi) Get employee name, project name, order by first name from employee detail & project
detail for those employee who have not assigned project.
SQL>Selectemp.name from emp join project on emp.id, project.id where original=’no’;
NAME
Harden
Sumitha
Wakarimashita
(vii) Display emp_name, project name from emp_detail&project_detail for all employees if
not project is assigned then display no project assigned.
SQL>select emp.name,emp.pnameproject.assign from emp join project on emp.id= project.id;
NAME PROJECT_NAME
Aikon Not Assigned
Ovonel Not Assigned
Durantula Not Assigned
18
(viii) Get all project name even they have not matching any emp_id in the left table order
by first name from emp_detail&project_detail.
SQL> Selectproject_namefrom emp1 left outer join project on emp1.eid = project.p_id;
PROJECT_NAME
Machine learning
Big data
Cache developement
(ix) Write a query to fetch emp.name & project who has assigned more than one project.
SQL>select ename,pname from emp1.join project on emp1.eid = project.eid where
pname in (Select ename from emp1 group by pname having count(*)>1);
ENAME PROJECT_NAME
Ni san Machine Learning
Ni san Biometrics
RESULT:
Thus SQL joins are executed to combine data from multiple tables and output
validated.
19
EX NO : 06 SQL SUB QUIRES
* Nested Queries
DATE :
AIM:
To perform Sub Queries using DML command.
20
(iii) Subqueries with the UPDATE Statement
WHERE AGE IN (SELECT AGE FROM CUSTOMERS_BKP WHERE AGE >= 29);
RESULT:
Hence the SQL subqueries executed to retrieve specific data subsets and output
validated.
21
EX NO : 07 DB OBJECTS CREATION OF DB VIEWS, SYNONYMS,
SEQUENCE, INDEXES, SAVE POINT.
DATE :
AIM:
To implement the creation of Views, Synonyms, Sequences, Indexes and Save point
using SQL.
(i) VIEWS:
View is a virtual table based on the result set of an SQL statement. It does not
physically exist. Rather, it is created by a query joining one or more tables.
Creating a View:
CREATE VIEW view_name AS
SELECT columns
FROM table
WHERE predicates;
Updating a View:
CREATE OR REPLACE VIEW view_name AS
SELECT columns
FROM table
WHERE predicates;
Dropping a View:
DROP VIEW view_name;
(ii) SYNONYMS:
Synonyms are alternate names for an existing object which are permanently stored in
the database. The various objects for which synonyms can be created are as follows:
❖ Tables
❖ Views
❖ Materialized Views
❖ Stored Function
❖ Stored Procedures
❖ Packages
❖ Sequences and Synonyms
22
Now SCOTT user can create and use synonyms.
SQL > create synonym EMPLOYEE for EMP;
Synonym created.
SQL > select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL
7369 SMITH CLERK 7902 17-DEC-80 800
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
SQL > select * from employee;
EMPNO ENAME JOB MGR HIREDATE SAL
7369 SMITH CLERK 7902 17-DEC-80 800
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
Granting Privileges:
❖ Granting privileges on the SYNONYM grants the privileges on the actual object.
❖ Suppose SCOTT user gives SELECT permission on EMPLOYEE synonym to JOHN
user then JOHN user will actually be given the specified permission on both the
synonym and the actual table.
SQL > connect scott/tiger @xe
SQL > grant select on employee to john;
Grant succeeded.
SQL > connect john/john @ xe
Connected.
SQL > select * from scott.employee;
EMPNO ENAME JOB MGR HIREDATE SAL
7369 SMITH CLERK 7902 17-DEC-80 800
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
SQL > select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL
7369 SMITH CLERK 7902 17-DEC-80 800
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
23
Data Dictionary for Synonyms:
“USER_SYNONYMS” is the data dictionary for synonyms.
SQL > select * from user_synonyms;
SYNONYM_NAME TABLE_OWNER TABLE_NAME DB_LINK
EMPLOYEE SCOTT EMP -
Dropping Synonym:
The DROP SYNONYM command can be used to remove a synonym.
(iii) SEQUENCES:
Sequence can be used to generate numbers in a sequence. This can be used to generate
values for primary keys.
Creating Sequence:
CREATE SEQUENCE <sequence_name>
START WITH <integer_value>
INCREMENT BY <integer_value>
MAXVALUE <integer_value> OR NOMAXVALUE
MINVALUE <integer_value> OR NOMINVALUE
CYCLE OR NOCYCLE
CACHE OR NOCACHE
ORDER OR NOORDER
❖ INCREMENT BY <integer_value>:
➢ The integer number by which the sequence number should be incremented for
generating the next number. If it is positive, then values are ascending, and if it
is negative, then values are descending. The default value is 1.
❖ MAXVALUE <integer_value>:
➢ If the increment value is positive, then MAXVALUE determines the maximum
value up to which the sequence numbers will be generated.
❖ NOMAXVALUE:
➢ Specifies a maximum value of 10^27 for an ascending sequence or -1 for a
descending sequence.
❖ MINVALUE <integer_value>:
➢ If the increment value is negative, then MINVALUE determines the minimum
value up to which the sequence numbers to be generated.
24
❖ NOMINVALUE:
➢ Specifies a minimum value of 1 for an ascending sequence and -10^26 for a
descending sequence.
❖ CYCLE:
➢ Causes the sequences to automatically recycle to the min value when the max
value is reached for ascending sequences; for descending sequences, it causes a
recycle from the min value back to the max value.
❖ NOCYCLE:
➢ Sequence numbers will not be generated after reaching the maximum value for
an ascending sequence or minimum value for a descending sequence.
❖ CACHE:
➢ Specifies how many values are pre-allocated in buffers for faster access. The
default value is 20.
❖ NOCACHE:
➢ Sequence numbers are not pre-allocated.
❖ ORDER:
➢ Generate the numbers in a serial order.
❖ NOORDER:
➢ Generate the numbers in a random order.
For example,
SQL > create sequence seq_empno
start with 1000
increment by 1
maxvalue 9999
nocycle
cache 2
order
/
Sequence created.
Initializing Sequence:
A sequence needs to be initialized before being used. Every sequence is initialized by
a pseudo-column NEXTVAL. Initialization means the START WITH <value> is assigned to
the sequence.
SQL > select seq_empno.nextval from dual;
NEXTVAL
1000
25
Determining the Last Running Sequence Number:
We can query the sequence for the currently held value by using the pseudo-column
CURRVAL meaning the current value.
SQL > select seq_empno.currval from dual;
CURRVAL
1000
Modifying Sequence:
SQL > alter sequence seq_empno INCREMENT BY 2
Sequence altered.
SQL > select seq_empno.currval from dual;
CURRVAL
1002
SQL > select seq_empno.nextval from dual;
NEXTVAL
1004
Dropping Sequence:
SQL > drop sequence seq_empno;
Sequence dropped.
26
User Allowing SCOTT to create synonym:
SQL > connect sys/sys @xe as sysdba -- Let us log in as SYS DBA
Connected.
SQL > grant create synonym to scott; -- Grant CREATE SYNONYM privilege to
SCOTT user
Grant succeeded.
Granting Privileges:
❖ Granting privileges on the SYNONYM grants the privileges on the actual object.
❖ Suppose SCOTT user gives SELECT permission on EMPLOYEE synonym to JOHN
user then JOHN user will actually be given the specified permission on both the
synonym and the actual table.
SQL > connect scott/tiger @xe
SQL > grant select on employee to john;
Grant succeeded.
SQL > connect john/john @ xe
Connected.
27
Grantee (John) creating synonym for grantors (Scott) table:
SQL > connect scott/tiger @ xe
Connected.
SQL > grant select on emp to john;
Grant succeeded.
SQL > connect john/john @ xe
Connected.
SQL > create synonym EMPLOYEE for scott.emp;
Synonym created.
SQL > select * from employee;
EMPNO ENAME JOB MGR HIREDATE SAL
7369 SMITH CLERK 7902 17-DEC-80 800
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
Dropping Synonym:
The DROP SYNONYM command can be used to remove a synonym.
SQL > drop synonym employee;
Synonym Dropped.
(iv) INDEXES:
Index is an object which can be defined as the ordered list of values of a column or
combination of columns used for faster searching and sorting of data.
Creating Index:
SQL > create index ind_student_college on student(college);
Index created.
Where ind_student_college is the user-defined name for the index object.
Removing Index:
SQL > drop index ind_student_college;
Index dropped.
28
(v) SAVE POINT:
Oracle provides a feature wherein we can define save points in between various DML
(insert, update, delete) operations so that at a later stage we can rollback changes to a specific
save point.
RESULT:
Thus the creation of database objects such as views, synonyms, sequences, indexes,
and save points commands in SQL are performed and output verified.
29
EX NO : 08 BASICS OF PL/SQL BLOCK TO SATISFY SOME CONDITIONS
by accepting input from the user and handling different types of exception.
DATE :
AIM:
To write PL/SQL programs using procedures and functions.
DESCRIPTION:
PL / SQL PROGRAMMING:
❖ DECLARE- This section starts with the keyword DECLARE. It is an optional section
and defines all variables, cursors, subprograms, and other elements to be used in the
program.
30
Decision Making With If Statement :-
The general syntax for the using IF—ELSE statement is
IF(TEST_CONDITION) THEN
SET OF STATEMENTS ELSE
SET OF STATEMENTS END IF;
LOOPING STATEMENTS:-
For executing the set of statements repeatedly we can use loops. The oracle supports
number of looping statements like GOTO, FOR, WHILE & LOOP.
Here is the syntax of these all the types of looping statements.
GOTO STATEMENTS
<<LABEL>>
SET OF STATEMENTS
GOTO LABEL;
FOR LOOP:
FOR <VAR> IN [REVERSE] <INI_VALUE>..<END_VALUE>
SET OF STATEMENTS
END LOOP;
WHILE LOOP:
WHILE (CONDITION) LOOP SET OF STATEMENTS
END LOOP;
LOOP STATEMENT:
LOOP
SET OF STATEMENTS IF (CONDITION) THEN EXIT
SET OF STATEMENTS END LOOP;
While using LOOP statement, we have to take care of EXIT conditions; otherwise it
may go into infinite loop.
PROCEDURES
SYNTAX:
31
PROBLEMS:
OUTPUT:
SQL>set serverout on;
SQL>/
Procedure created. SQL>exe pro1(4) 1
2
3
4
PL/SQL procedure successfully completed.
(ii) Create a table employee which has the following columns eno,ename,sal and write a
procedure to display the employee details of given employee number.
PROCEDURE:
create or replace procedure p3(num number) is
erec emp%rowtype;
begin
select eno, ename into erec.eno, erec.ename from emp where eno=num;
dbms_output.put_line('Employee number: ' || erec.eno);
dbms_output.put_line('Employee name: ' || erec.ename);
exception
when no_data_found then
dbms_output.put_line('No record found');
end;
MAIN PROGRAM:
declare
num emp.eno%type;
salary emp.sal%type;
begin
num := #
salary := fun1(num);
if salary = -1 then
dbms_output.put_line('No records available with employee number: ' || num);
else
dbms_output.put_line('Salary of employee number ' || num || ' is: ' || salary);
end if;
end;
32
OUTPUT:
SQL>set serverout on;
SQL>/
SQL>execp2(4); Factorial of 4 is :24
PL/SQL procedure successfully completed.
33
(v) Write a procedure to find the greatest of three numbers.
SQL> set serveroutput on;
SQL> declare
a number(7);
b number(7);
c number(7);
begin
a:=&a;
b:=&b;
c:=&c;
if(a>b and a>c) then
dbms_output.put_line (' The greatest of the three is ' || a);
else if (b>c) then
dbms_output.put_line (' The greatest of the three is ' || b);
else
dbms_output.put_line (' The greatest of the three is ' || c);
end if;
end if;
end;
/
OUTPUT:
Enter value for a: 5 old 6: a:=&a;
new 6: a:=5;
Enter value for b: 7 old 7: b:=&b;
new 7: b:=7;
Enter value for c: 1 old 8: c:=&c;
new 8: c:=1;
The greatest of the three is 7
PL/SQL procedure successfully completed.
(vi) Write a procedure to print numbers from 1 to 5 using simple loop
SQL> set serveroutput on;
SQL> declare
a number:=1;
begin
loop
dbms_output.put_line (a);
a:=a+1;
exit when a>5;
end loop;
end;
/
OUTPUT:
1
2
3
4
5
PL/SQL procedure successfully completed.
34
(vii) Write a procedure to print numbers from 1 to 4 using while loop
SQL> set serveroutput on;
SQL> declare
a number:=1;
begin
while(a<5)
loop
dbms_output.put_line (a);
a:=a+1;
end loop;
end;
10 /
OUTPUT:
1
2
3
4
PL/SQL procedure successfully completed.
OUTPUT:
1
2
3
4
5
PL/SQL procedure successfully completed.
35
FUNCTIONS:
SYNTAX:
MAIN PROGRAM:
declare
num emp.eno%type; salary emp.sal%type;
begin
num :=# salary:=fun 1(num); if(salary =-1)then
dbms_output.putline(‘No records available with employee number: ‘|| num); else
dbms_output.putline(‘Salary of employee number ‘||num ||’is:’||salary); end if;
end;
OUTPUT:
SQL>/
Function created SQL>/
36
(ii) Create a function to calculate the factorial of given number.
create or replace function fact(n in number)
return number
is
s number;
begin
s := 1;
if n = 0 then
return 1;
end if;
for i in 1..n loop
s := s * i;
end loop;
return s;
end;
/
Function created.
SQL>select fact(10) from dual;
OUTPUT:
FACT(10)
-------------
3628800
OUTPUT:
Enter value for endvalue: 20 Old 6: endvalue :=&endvalue; New 6:endvalue:=20;
Sum of odd numbers between 1 and 20 is 100 PL/SQL procedure successfully
completed.
37
(iv) Create a function to display the table details.
SQL> create table pupil (name varchar2(10), age number(3));
Table created.
exist
Not exist
RESULT:
Thus PL / SQL block executed successfully to satisfy specified conditions.
38
EX NO : 09 FRAME AND EXECUTE THE APPROPRIATE PL/SQL CURSORS
DATE :
AIM:
To implement PL/SQL cursors to fetch and process data, framing explicit and implicit
cursors for database operations in a structured manner.
PROCEDURE:
Create a PL/SQL block with an explicit cursor to fetch data from a specific table:
39
(ii) Framing and Executing Implicit Cursor:
RESULT:
Thus PL / SQL block executed successfully to satisfy specified conditions.
40
EX NO : 10 CREATION OF DATABASE TRIGGERS
DATE :
AIM:
To Develop insert, delete, and update triggers to automate actions, maintain data
integrity, and enhance functionality within the database system.
(i) Create a row level trigger for the customers table that would fire for INSERT or
UPDATE or DELETE operations performed on the CUSTOMERS table.
This trigger will display the salary difference between the old values and new values:
CUSTOMERS TABLE:
INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (7,
'Kriti', 22, 'HP', 7500.00 );
Old salary:
New salary: 7500
Salary difference:
41
(ii) Convert employee name into uppercase whenever an employee record is inserted
or updated. Trigger to fire before the insert or update.
Table created.
Trigger created.
1 row created.
42
SQL> INSERT INTO Employee(ID, First_Name, Last_Name, Start_Date,
End_Date, Salary, City, Description)
2 VALUES('04','Celia', 'Rice', TO_DATE('19821024','YYYYMMDD'),
TO_DATE('19990421','YYYYMMDD'), 2344.78,'Vancouver','Manager')
3 /
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> SELECT *
2 FROM Employee
3 /
43
ID FIRST_NAME LAST_NAMESTART_DATEND_DATE SALARY CITY DESCRIPTION
8 rows selected.
SQL> drop table Employee 2 / Table dropped.
(iii) Trigger before deleting a record from emp table. Trigger will insert the row to
be deleted into another table and also record the user who has deleted therecord.
44
SQL> delete from employee; 8 rows deleted. SQL> select * from employee_audit;
8 rows selected.
SQL>drop tableemployee_audit;
Table dropped.
RESULT:
Thus Database triggers successfully created to automate actions, enforce data integrity,
and enhance functionality within the database system.
45
EX NO : 11 FRAME AND CREATE THE APPROPRIATE EXCEPTION
HANDLING FOR THE PROJECT
DATE :
AIM:
To write PL/SQL procedures using Exception handling for manipulating the
tables/database
EXCEPTION:
An exception is an error which disrupts the normal flow of program instructions.
PL/SQL provides us the exception block which raises the exception thus helping the
programmer to find out the fault and resolve it.
Syntax:
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
Exception1-handling-statements
WHEN exception2 THEN
Exception2-handling-statements
WHEN exception3 THEN
Exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements
END;
46
OUTPUT:
(i) PL/SQL procedure to handle in build exceptions while manipulating the table :
47
(ii) PL/SQL for user defined exception while manipulating the table :
RESULT:
Thus framing and creating an appropriate Exception Handling for the project is
executed successfully.
48
EX NO : 12 CREATION OF FUNCTIONS FOR THE PROJECT
DATE :
AIM:
To Create functions for the project in the database.
PROCEDURE
Function is created using the CREATE FUNCTION statement. The simplified syntax
for the CREATE OR REPLACE PROCEDURE statement
CREATE [OR REPLACE] FUNCTION function_name
[(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN return_datatype
{IS | AS}
BEGIN
< function_body >
END [function_name];
TABLE : STUDENTS
Create a PL/SQL function to find the total of all marks of the students
49
Calling the PL/SQL function to calculate the total of one student
Display the records of students table after calling the PL/SQL function
RESULT:
Thus the creation and execution of functions for the project were completed
successfully.
50
EX NO : 13 CREATION OF DATABASE TRIGGERS
DATE :
AIM:
The aim of this experiment is to understand the concept of PL/SQL procedures,
including their structure, parameters, and execution, and to frame and execute PL/SQL
procedures with appropriate SQL comments.
PROCEDURE:
51
ELSE
DBMS_OUTPUT.PUT_LINE('Error: Division by zero.');
END IF;
END DivideNumbers;
/
Declare variable to capture output parameter
DECLARE
result NUMBER;
BEGIN
Execute the procedure with sample input values and capture output
DivideNumbers(10, 5, result);
DBMS_OUTPUT.PUT_LINE('Result: ' || result);
END;
RESULT:
The above PL/SQL procedures were executed successfully, and their output/results
were displayed using DBMS_OUTPUT.PUT_LINE statements.
52
EX NO : 14 DESIGN OF AIRLINE RESERVATION MANAGEMENT SYSTEM
DATE :
AIM:
The aim of this experiment is to design and construct an Entity-Relationship (ER)
model and ER diagram tables for the Airline Reservation Management System .
REQUIREMENTS:
❖ Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
❖ MySQL 5.6.1
PROCEDURE:
(i) Identifying Entities and Attributes:
➢ Analyze the application domain and identify relevant entities and their
attributes.
➢ Create a list of entities and their respective attributes based on the
requirements.
53
ENTITIES:
❖ Passengers
➢ Attributes:
● PassengersID (Primary Key),
● Name,
● Address,
● Email,
● Phone,
● DateOfBirth
❖ Flight Attendant
➢ Attributes:
● Flight Attendant ID (Primary Key),
● Name,
● Email,
● Phone,
● Education
❖ Flight
➢ Attributes:
● FlightID (Primary Key),
● FlightName,
● Routes
RELATIONSHIPS:
❖ Enrollment
➢ Links Passengers and Flight Entities
➢ Attributes: EnrollmentID (Primary Key), PassengersID (Foreign Key),
FlightID (Foreign Key), Duration, Year, Grade, etc.
❖ Teaching
➢ Links Flight Attendant and Flight Entities
➢ Attributes: TeachingID (Primary Key), Flight Attendant ID (Foreign Key),
FlightID (Foreign Key), Duration, Year, etc.
54
E-R Model
Attributes of the following Entities
(i) PASSENGERS
❖ PassengersID (Primary Key)
❖ Name
❖ Address
❖ Email
❖ Phone
❖ Date Of Birth
❖ Gender
SCHEMA
Passengers: PassengersID (Primary Key), Name, Address, Email, Phone, DateOfBirth
55
(ii) FLIGHT ATTENDANT
❖ Flight Attendant ID (Primary Key),
❖ Name,
❖ Email,
❖ Phone,
❖ Address
SCHEMA
Flight Attendant : Flight Attendant ID (Primary Key), Name, Email, Phone
56
(iii) FLIGHT
❖ FlightID (Primary Key),
❖ FlightName,
❖ Route
❖ Duration
❖ FlightType
SCHEMA
Flight: FlightID (Primary Key), FlightName, Route, Duration, FlightType
57
(iv) LOCATION
❖ Loc_ID (Primary Key)
❖ Loc_desc
❖ Loc_type
SCHEMA
Location: Loc_ID (Primary Key), Loc_desc, Loc_type
58
(v) RESERVATION
❖ Reg_ID (Primary Key)
❖ Reg_desc
❖ Reg_type
❖ Reg_date
SCHEMA
Reservation: Reg_ID (Primary Key), Reg_desc, Reg_type, Reg_date
59
(vi) PERMISSION
❖ Per_id (Primary Key)
❖ Per_role_id
❖ Per_module
❖ Per_name
SCHEMA
Permission: Per_id (Primary Key), Per_role_id, Per_module, Per_name
60
(vii) ROLES
❖ Role-id (Primary Key)
❖ Role_name
❖ Role_desc
SCHEMA
Roles: Role-id (Primary Key), Role_name, Role_desc
61
(viii) LOG-IN
❖ Login-ID (Primary Key)
❖ Login-role-ID
❖ Login_username
❖ Login_password
SCHEMA
Login: Login-ID (Primary Key), Login-role-ID, Login_username, Login_password
62
ER DIAGRAM FOR AIRLINE RESERVATION MANAGEMENT SYSTEM
63
Passengers Table:
❖ Contains details like ID, name, contact information, and password for
passengers. It's crucial for passenger record management, enrollment, and
authentication.
Flight Table:
❖ Stores essential information about Flightes, including ID, name, description,
type, and passenger enrollment details. It aids in Flight management and
tracking passenger enrollments.
Location Table:
❖ Holds data about locations within the university, such as IDs, descriptions, and
types. It’s useful for organizing academic units and allocating resources.
Reservation Table:
❖ Tracks passenger reservations with ID, description, type, and reservation date.
It's pivotal for monitoring enrollment trends and managing Flight capacities.
Permission Table:
❖ Manages access permissions with unique IDs, role associations, module
details, and permission names. It ensures secure data access and user
management.
Roles Table:
❖ Defines roles with IDs, names, and descriptions. It's essential for role-based
access control and user administration.
Log-In Table:
❖ Logs login activities with unique IDs, role associations, usernames, and
passwords. It’s critical for security monitoring and audit trails.
RESULT:
Hence, the Entity-Relationship (ER) model and ER diagram tables were successfully
designed for the Airline Reservation Management System .
64
EX NO : 15 DEPLOYMENT OF AIRLINE RESERVATION MANAGEMENT SYSTEM
DATE :
AIM:
To integrate a airlines database management system aimed at streamlining Flight
Reservation, including managing passenger records, Flight information, and
reservation tasks effectively.
65
USER INTERFACE:
TABLE CREATION:
DATA INSERTION:
INSERT INTO `passenger_profile` (`passenger_id`, `user_id`, `flight_id`, `mobile`,
`dob`, `f_name`, `m_name`, `l_name`) VALUES
(1, 1, 23, '9845514598', '1995-01-01 00:00:00', 'Sottai ', '', 'Saalaa'),
(2, 2, 22, '9791528988', '1995-02-13 00:00:00', 'Sottai', '', 'Rishi'),
(3, 3, 24, '9845214987', '1994-06-21 00:00:00', 'Koratur ', '', 'Kulla'),
(4, 4, 25, '965485469', '1995-05-16 00:00:00', 'Santhosh', '', 'Maami'),
(5, 2, 26, '7854444411', '1995-02-13 00:00:00', 'Sottai', '', 'Rishi');
66
❖ The query inserts multiple records into the passenger_profile table with values for the
passenger_id, user_id, flight_id, mobile, dob, f_name, m_name, and l_name columns.
❖ Each record represents a passenger's profile with details like name, mobile number,
date of birth, and associated user and flight IDs.
SQL TABLE :
USER INTERFACE:
67
(iii) LIST OF FLIGHT
TABLE CREATION:
❖ The query creates a table named flight with fourteen columns: flight_id, admin_id,
arrivale, departure, Destination, source, airline, Seats, duration, Price, status, issue,
last_seat, bus_seats, and last_bus_seat.
❖ The table uses the InnoDB storage engine and has a default character set of latin1 with
a case-insensitive collation of latin1_swedish_ci.
DATA INSERTION:
INSERT INTO `flight` (`flight_id`, `admin_id`, `arrivale`, `departure`, `Destination`,
`source`, `airline`, `Seats`, `duration`, `Price`, `status`, `issue`, `last_seat`, `bus_seats`,
`last_bus_seat`) VALUES
(22, 1, '2024-04-22 13:30:00', '2024-04-22 10:00:00', 'Trerdence', 'Yleigh', 'Sottai
Airlines', '72', '3 hrs', 8000, 'dep', '', '', 20, ''),
(23, 1, '2024-04-23 08:00:00', '2024-04-22 09:00:00', 'Otiginia', 'San', 'Saalaa Airlines',
'81', '10hrs', 15000, '', '', '', 20, ''),
(24, 1, '2024-04-22 11:00:00', '2024-04-22 08:00:00', 'Vrexledo', 'Plueyby', 'Qatar
Airways', '286', '3hrs', 6500, 'dep', '', '', 20, ''),
(25, 1, '2024-04-22 09:30:00', '2024-04-22 07:00:00', 'Flerough', 'Yleigh', 'Air India',
'231', '2hrs 30min', 8200, '', '', '', 20, ''),
(26, 1, '2024-04-22 10:00:00', '2024-04-22 07:30:00', 'Chiby', 'Odonhull', 'Indigo',
'245', '2hrs 30min', 7500, '', '', '', 20, '');
❖ The query inserts multiple records into the flight table with values for the flight_id,
admin_id, arrivale, departure, Destination, source, airline, Seats, duration, Price,
status, issue, last_seat, bus_seats, and last_bus_seat columns.
❖ Each record represents a flight with details like departure and arrival times,
destination, source, airline, seat availability, price, and status.
68
SQL TABLE :
USER INTERFACE:
69
(iv) LIST OF AIRLINES
TABLE CREATION:
❖ The query creates a table named airline with three columns: airline_id, name, and
seats.
❖ The table uses the InnoDB storage engine and has a default character set of latin1 with
a case-insensitive collation of latin1_swedish_ci.
DATA INSERTION:
SQL TABLE :
70
USER INTERFACE:
❖ The query attempts to create a table named schedule_list with seven columns:
flight_id, admin_id, arrivale, departure, Destination, source, and airline.
❖ The table uses the InnoDB storage engine and has a default character set of latin1 with
a case-insensitive collation of latin1_swedish_ci. However, there's a syntax error due
to an extra comma after the duration column definition.
DATA INSERTION:
INSERT INTO `flight` (`flight_id`, `admin_id`, `arrivale`, `departure`, `Destination`,
`source`, `airline`, `Seats`, `duration`, `Price`, `status`, `issue`, `last_seat`, `bus_seats`,
`last_bus_seat`) VALUES
(26, 1, '2024-04-22 10:00:00', '2024-04-22 07:30:00', 'Chiby', 'Odonhull', 'Indigo',
'245', '2hrs 30min', 7500, '', '', '', 20, '');
❖ The query attempts to insert a record into the flight table with values for the flight_id,
admin_id, arrivale, departure, Destination, source, airline, Seats, duration, Price,
status, issue, last_seat, bus_seats, and last_bus_seat columns.
❖ The record represents a flight with specific details like departure and arrival times,
destination, source, airline, seat availability, price, and status.
71
SQL TABLE :
USER INTERFACE:
RESULT:
Hence, The Deployment of the Airline Reservation Management System involves
designing the database, creating the model, SQL Tables and implementing the model to
ensure effective data management.
72