Rdbms Record
Rdbms Record
10
CONTENTS
CONTENTS
9
GROUP-A
EX.NO : 1
Create a student table with the following attributes name, register number,
DATE :
department, marks in 5 subjects and total.
AIM:
PROCEDURE:
QUERIES:
Table Creation student_table:
name VARCHAR(51),
department VARCHAR(51),
subject1 INT,
subject2 INT,
subject3 INT,
subject4 INT,
subject5 INT,
total INT
);
Table created.
desc student11
Object Type TABLE ObjectSTUDENT11
STUDEN
NAME Varchar2 51 - - - - -
T11
REGISTER_NU
Number - - 0 1 - - -
MBER
DEPARTMENT Varchar2 51 - - - - -
SUBJECT1 Number - - 0 - - -
SUBJECT2 Number - - 0 - - -
SUBJECT3 Number - - 0 - - -
SUBJECT4 Number - - 0 - - -
SUBJECT5 Number - - 0 - - -
TOTAL Number - - 0 - - -
(a) Insert few records into student table.
INSERT INTO
student11(name,register_number,department,subject1,subject2,subject3,subject4,subject5,total)
VALUES('Alice',101,'Computer Science',85,90,88,92,87,442);
1 row(s) inserted.
INSERT INTO
student11(name,register_number,department,subject1,subject2,subject3,subject4,subject5,total)
VALUES('Bob',102,'Mechanical Engineering',75,80,78,82,77,392);
1 row(s) inserted.
INSERT INTO
student11(name,register_number,department,subject1,subject2,subject3,subject4,subject5,total)
VALUES('Charlie',103,'Electrical Engineering',65,70,68,72,67,342);
1 row(s) inserted.
SELECT*FROM student11;
Total
RESULT:
EX.NO : 2
Create a student table with the following attributes name, register number,
department, marks in 5 subjects and total
DATE :
AIM:
PROCEDURE:
QUERIES:
Table Creation student_table:
name VARCHAR(50),
department VARCHAR(50),
subject1 INT,
subject2 INT,
subject3 INT,
subject4 INT,
subject5 INT,
total INT
);
Table created
desc student15
STUDEN
NAME Varchar2 50 - - - - -
T15
REGISTER_NU
Number - - 0 1 - - -
MBER
DEPARTMENT Varchar2 50 - - - - -
SUBJECT1 Number - - 0 - - -
SUBJECT2 Number - - 0 - - -
SUBJECT3 Number - - 0 - - -
SUBJECT4 Number - - 0 - - -
SUBJECT5 Number - - 0 - - -
TOTAL Number - - 0 - - -
(a) Insert few records into student table.
INSERT INTO
student15(name,register_number,department,subject1,subject2,subject3,subject4,subject5,total)
VALUES('Alice',211278019,'Computer Science',85,90,88,92,87,442);
1 row(s) inserted.
INSERT INTO
student15(name,register_number,department,subject1,subject2,subject3,subject4,subject5,total)
VALUES('Bob',211278005,'Mechanical Engineering',75,90,78,82,77,392);
1 row(s) inserted.
INSERT INTO
student15(name,register_number,department,subject1,subject2,subject3,subject4,subject5,total)
VALUES('Charlie',211278003,'Electrical Engineering',65,70,68,72,67,342);
1 row(s) inserted.
(b) Modify the name of the student as vignesh whose register number is
211278019.
UPDATE student15
SET name='Vignesh'
WHERE register_number=211278019;
1 row(s) updated
.
(c) Delete the records whose register number is 211278005.
SELECT*FROM student15;
RESULT:
EX.NO : 3
Create a table student with name, roll number, gender, age and mobile
number. Apply the following integrity rules to the student table
DATE :
AIM:
PROCEDURE:
QUERIES:
Table Creation student_table:
name VARCHAR(100)CHECK(name=UPPER(name)),
mobile_number VARCHAR(15)
);
Table created.
desc student17
ROLL_NUMB
Number - - 0 - - -
ER
GENDER Varchar2 10 - - - - -
AGE Number - - 0 - - - -
MOBILE_NU
Varchar2 15 - - - - -
MBER
1-5
VALUES('ALICE',2024,'Male',12,1234567891);
1 row(s) inserted
VALUES('KAVITHA',2025,'Female',12,1234567845);
1 row(s) inserted
INSERT INTO student17(name,roll_number,gender,age,mobile_number)
VALUES('KAYAL',2026,'Female',12,1234567234);
1 row(s) inserted
SELECT*FROM student17;
NAME
ALICE
KAVITHA
KAYAL
ROLL_NUMBER
2024
2025
2026
AGE
12
12
12
GENDER
Male
Female
Female
(e) The mobile number may contain null values.
MOBILE_NUMBER
1234567891
1234567845
1234567234
RESULT:
EX.NO : 4
Create a table student_master with the following attributes name,
DATE :
regno, dept and year of joining with suitable data types. Use Select
command to do the following.
AIM:
PROCEDURE:
QUERIES:
create table student35(
name varchar(10),
regno number(3),
dept varchar(5),
year number(4));
Table created.
1 row(s) inserted
1 row(s) inserted
1 row(s) inserted
1 row(s) inserted
1 row(s) inserted
select*from student35;
NAME REGNO DEPT YEAR
nagaraj 123 tamil 1978
durga 124 eng 1980
rathi 125 cs 1999
rathi 125 cs 1999
sathya 126 mat 2008
NAME
nagaraj
durga
rathi
rathi
sathya
(c) Eliminate the duplicate entry in student_mastertable.
RESULT:
EX.NO : 5
Create a table sales_order_details with the s_order_no as primary key and
itcontains the following fields: product_no, description, qty_ordered,
DATE :
qty_disp,product_rate, profit_percent, sell_price, supplier_name. Use Select
command to do the following
AIM:
PROCEDURE:
QUERIES:
Create table sales_order_details22:
Table created.
Desc sales_order_details22
QTY_DISP Number - - 0 - - -
PRODUCT_R
Number - 10 2 - - -
ATE
PROFIT_PER
Number - 5 2 - - -
CENT
SELL_PRICE Number - 10 2 - - -
SUPPLIER_N
Varchar2 100 - - - - -
AME
Table created.
INSERT INTO
sales_order_details22(s_order_no,product_no,description,qty_ordered,qty_disp,product_rate,p
rofit_percent,sell_price,supplier_name)
VALUES(3456,123,'notes',45,56,67.0,0.50,1.50,'priya');
1 row(s) inserted.
INSERT INTO
sales_order_details22(s_order_no,product_no,description,qty_ordered,qty_disp,product_rate,profit_pe
rcent,sell_price,supplier_name)
VALUES(3455,125,'paper',45,56,68.0,0.50,1.50,'dharma');
1 row(s) inserted.
INSERT INTO
sales_order_details22(s_order_no,product_no,description,qty_ordered,qty_disp,product_rate,profit_pe
rcent,sell_price,supplier_name)
VALUES(3457,126,'book',45,56,69.0,0.50,1.50,'jim');
1 row(s) inserted.
SELECT*FROM sales_order_details22;
(a) Select each row and compute sell_price*.50 and sell_price*1.50 for each row
selected.
SELECT s_order_no,product_no,description,
sell_price*0.50 AS sell_price_half,
sell_price*1.50 AS sell_price_one_and_half
FROM sales_order_details22;
SELECT product_no,profit_percent,sell_price
FROM sales_order_details22;
SELECT product_no,description,profit_percent,sell_price
FROM sales_order_details22
(d) Select the suppliername and product_no where suppliername has ‘r’ or ‘h’as
second character.
SELECT supplier_name,product_no
FROM sales_order_details22
WHERE supplier_name LIKE'_r%'OR supplier_name LIKE'_h%';
SUPPLIER_NAME PRODUCT_NO
priya 123
dharma 125
RESULT:
EX.NO : 6 Create an Employee table with the following attributes: employee_number,
name, job and manager_id. Set the manager_id as a foreign key for creating
self referential structure.
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table Employee:
name VARCHAR(100),
job VARCHAR(100),
manager_id VARCHAR(100)
);
Table created.
desc Employee12
EMPLOYEE_
EMPLOYEE12 Number - - 0 1 - - -
NUMBER
MANAGER_I
Varchar2 100 - - - - -
D
1-4
VALUES('Bharathi',93456,'Financial Analystic',2203416);
1 row(s) inserted.
VALUES('Kavitha',12346,'Administrator',2276549);
1 row(s) inserted.
INSERT INTO Employee12(name,Employee_number,job,manager_id)
VALUES('Pothumani',12347,'Information Technology',222456);
1 row(s) inserted.
(c) Display the employee details who are working under particular
manager_id.
SELECT manager_id FROM Employee12;
MANAGER_ID
2203416
2276549
222456
RESULT:
EX.NO : 7 Create an Employee table with the following attributes: employee_number,
employee_name, department_number, job and salary.
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table Employee:
CREATE TABLE Employee29(
employee_number INT PRIMARY KEY,
employee_name VARCHAR(100),
department_number INT,
job VARCHAR(50),
salary DECIMAL(10,2)
);
Table created.
desc Employee29
EMPLOYEE_N Varcha
100 - - - - -
AME r2
DEPARTMENT Numbe
- - 0 - - -
_NUMBER r
Varcha
JOB 50 - - - - -
r2
Numbe
SALARY - 10 2 - - -
r
1-5
VALUES(56789,'saran',123,'IT',32000.00);
1 row(s) inserted.
VALUES(56786,'ranjani',126,'tamil',34000.00);
1 row(s) inserted.
SELECT*FROM Employee29;
(a) Query to display the employee_name and Salary of all the employees earning
more than 20000 INR.
SELECT employee_name,salary
FROM Employee29
WHERE salary>30000;
EMPLOYEE_NAME SALARY
saran 32000
ranjani 34000
FROM Employee29
WHERE employee_number=56786;
EMPLOYEE_NAME DEPARTMENT_NUMBER
ranjani 126
(c) Query to display employee_name and Salary for all employees whose salary is
not in the range of INR 15000 and INR 30000.
SELECT employee_name,salary
FROM Employee29
EMPLOYEE_NAME SALARY
saran 32000
ranjani 34000
RESULT:
EX.NO : 8 Create an Employee table with the following attribute employee_number,
employee_name, job_type, hire_date, department_number and salary.
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table Employee:
Table created
desc emp36
NAME Varchar2 10 - - - - -
JOB Varchar2 10 - - - - -
HIRE_DA
Date 7 - - - - -
TE
DEPTNO Number - - 0 - - -
SALARY Number - - 0 - - -
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
select*from emp35;
select name,deptno from emp35 where deptno in(10,20) order by name ASC;
NAME DEPTNO
aadhi 10
aadhi 10
raji 20
raji 20
(b) Query to display Name of all the employees where the third
letter of their
name is =A.
(c)Query to display Name with the 1st letter capitalized and all other letter
lowercase
INITCAP(NAME)
Aadhi
Raji
Shanmuga
Perumal
Aadhi
Raji
Shanmuga
Perumal
(d) Query to display Name of all employees either have two R‘s
or have two A‘s in their Name.
RESULT:
EX.NO : 9 Create an Employee table with the following attributes: employee_number,
name, job, hire_date and manager_id. Set the manager_id as a forein key for
creating selfreferential structure.
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table Employee:
references employee9(employee_number));
Table created.
desc employee9;
Table Column Data Type Length Precision Scale Primary Key Nullable Default Comment
EMPLOYEE_NUMBE
EMPLOYEE9 Number - - 0 1 - - -
R
NAME Varchar2 10 - - - - -
JOB Varchar2 10 - - - - -
HIREDATE Date 7 - - - - -
MANAGER_ID Number - - 0 - - -
1-5
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
(a) Query to display name and Hire Date of every Employee
who was hired in 2007.
=2007;
NAME HIREDATE
agash 21-DEC-07
select name,hiredate,months_between
(sysdate,hiredate)"months"
from employee9;
NAME JOB
ramesh supervisor
agash supervisor
RESULT:
GROUP-B
EX.NO : 10 Create a table sales_order with s_order_no, client_number,
delivery_address, delivery_date and order_status. Define the s_order_no as
primary key using column level
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table Employee:
primary key(sales_order_no));
Table created.
desc sales_order1
SALES_OR
SALES_ORDER1 Number - - 0 1 - - -
DER_NO
CLIENT_N
Number - - 0 - - -
O
DELIVERY_
Varchar2 30 - - - - -
ADDRESS
DELIVERY_
Date 7 - - - - -
DATE
ORDER_ST
Varchar2 10 - - - - -
ATUS
1-5
1 row(s) inserted.
values(12,22,'k,k,nagar chennai',to_date('14/02/2024','dd/mm/yyyy'),'shipped');
1 row(s) inserted.
insert into sales_order1
values(13,33,'kandhinagar',to_date('24/03/2024','dd/mm/yyyy'),'delivered');
1 row(s) inserted.
select*from sales_order1;
select*from sales_order1;
Table created.
select*from sales_order1_copy;
Table altered.
Table altered.
1 row(s) updated.
update sales_order1 set salesman_no=52
1 row(s) updated.
1 row(s) updated.
select*from sales_order1;
Table altered.
select*from sales_order1;
RESULT:
EX.NO : 11 Create an Employee table with the following attribute employee_number,
employee_name, job_type, hire_date, department_number, salary and
commission.
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table Employee:
employee_no int
,employee_name varchar(10),
job_type varchar(10),
hire_date date,
dept_no int,
salary number(10,2),
commission number(10,2));
Table created.
desc Employee09;
EMPLOYEE_NA
Varchar2 10 - - - - -
ME
JOB_TYPE Varchar2 10 - - - - -
HIRE_DATE Date 7 - - - - -
DEPT_NO Number - - 0 - - -
SALARY Number - 10 2 - - -
COMMISSION Number - 10 2 - - -
1-7
select*from Employee09;
HIGHEST_SALARY
43567
select min(salary) as lowest_salary from Employee09;
LOWEST_SALARY
15476
select sum(salary) as total_salary from Employee09;
TOTAL_SALARY
99041
select avg(salary) as average_salary from Employee09;
AVERAGE_SALARY
24760.25
select employee_no,employee_name from Employee09 where salary > (select avg(salary) from
Employee09);
EMPLOYEE_NO EMPLOYEE_NAME
123 kavi
EX.NO : 12
Create a DEPARTMENT table with the attributes of department_number
and department_name. Set the department_ number as a primary key.
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table Department:
department_name varchar(15));
Table created.
desc department12;
DEPARTMENT_NUM
DEPARTMENT12 Number - - 0 1 - - -
BER
DEPARTMENT_NAM
Varchar2 15 - - - - -
E
1-2
select*from department12;
DEPARTMENT_NUMBER DEPARTMENT_NAME
10 cs
20 his
30 eco
40 phy
50 eng
60 tam
foreign key(department_number)references
department12(department_number));
Table created.
desc employee12;
JOB Varchar2 10 - - - - -
DEPARTMENT_NUMB
Number - - 0 - - -
ER
1-4
1 row(s) inserted.
1 row(s) inserted.
insert into employee12 values(13,'maddy','incharge',30);
1 row(s) inserted.
1 row(s) inserted.
1 row(s) inserted.
select*from employee12;
JOB
incharge
teacher
staff
hod
supervisor
Employee_name_job
vadivel,hod
kannan,teacher
maddy,incharge
agash,staff
pavi,supervisor
ramesh,incharge
RESULT:
EX.NO : 13 Create a table client-master with the following fields: client_no, name,
address, city, state, pincode, remarks, bal_due with suitable data types.
DATE :
AIM:
PROCEDURE:
QUERIES:
bal_due number(5));
Table created.
desc client_master1;
Le
Data ng Precis Sca Primary Nulla Defa Comm
Table Column Type th ion le Key ble ult ent
CLIENT_ CLIENT_N
Number - 4 0 - - -
MASTER1 O
NAME Varchar2 6 - - - - -
ADDRESS Varchar2 15 - - - - -
CITY Varchar2 10 - - - - -
STATE Varchar2 10 - - - - -
PINCODE Number - 9 0 - - -
REMARKS Varchar2 3 - - - - -
BAL_DUE Number - 5 0 - - -
Table created.
desc supplier_master1;
SUPPLIER_MA CLIENT_
Number - 4 0 - - -
STER NO
NAME Varchar2 6 - - - - -
ADDRES
Varchar2 15 - - - - -
S
CITY Varchar2 10 - - - - -
STATE Varchar2 10 - - - - -
PINCOD
Number - 9 0 - - -
E
REMARK
Varchar2 3 - - - - -
S
BAL_DU
Number - 5 0 - - -
E
(b) rename the attribute client_no with supplier_no and the attribute name with
supplier_name in the supplier_master table
Table altered.
Table altered.
desc supplier_master1;
Data Len Preci Sc Primar Null Def Com
Table Column Type gth sion ale y Key able ault ment
SUPPLIER_ SUPPLIER
Number - 4 0 - - -
MASTER _NO
SUPPLIER
Varchar2 6 - - - - -
_NAME
ADDRESS Varchar2 15 - - - - -
CITY Varchar2 10 - - - - -
STATE Varchar2 10 - - - - -
PINCODE Number - 9 0 - - -
REMARKS Varchar2 3 - - - - -
BAL_DUE Number - 5 0 - - -
(111,'kannan','kk street','sivagangi','tamilnadu',656466,'no',1090);
1 row(s) inserted.
(111,'agash','sri street','madurai','tamilnadu',624601,'no',1200);
1 row(s) inserted.
(111,'kishor','circle street','kovai','tamilnadu',624601,'no',1030);
1 row(s) inserted.
(111,'logesh','loki street','chennai','tamilnadu',624601,'no',1009);
1 row(s) inserted.
select*from client_master1;
4 row(s) inserted.
(f) Delete the row which is having the value chennai in the city attribute of
client_master table.
1 row(s) deleted.
select*from client_master3;
AIM:
PROCEDURE:
QUERIES:
Create table master book:
magazine_name VARCHAR(100),
magazine_type VARCHAR(100),
magazine_price VARCHAR(100)
);
Table created.
desc master_book5
MASTER_BO MAGAZINE_C
Number - - 0 1 - - -
OK5 ODE
MAGAZINE_N
Varchar2 100 - - - - -
AME
MAGAZINE_T
Varchar2 100 - - - - -
YPE
MAGAZINE_P
Varchar2 100 - - - - -
RICE
VALUES(12345,'kalki','monthly',2000);
1 row(s) inserted.
INSERT INTO master_book6(magazine_code,magazine_name,magazine_type,magazine_price)
VALUES(12346,'science','weekly',4000);
1 row(s) inserted.
1 row(s) inserted.
SELECT*FROM master_book7;
VALUES(12348,'kumutham','weekly',10);
1 row(s) inserted
SELECT*FROM master_book8;
(a) PL/SQL block to perform insert, update and delete operations on the above table
UPDATE master_book7
WHERE magazine_name='science';
1 row(s) inserted
SELECT*FROM master_book7;
WHERE magazine_code=12346;
1 row(s) deleted.
SELECT*FROM master_book7;
AIM:
PROCEDURE:
QUERIES:
Create table contain:
user_name VARCHAR(100),
address VARCHAR(100)
);
Table created.
desc contain1
PHONE_NUM
CONTAIN1 Number - - 0 1 - - -
BER
1-3
VALUES(9923456172,'DHARMA','NO.556,chengalpattu,chennai,658360');
1 row(s) inserted.
VALUES(9923453452,'POTHU','NO.545,ram nagar,trichy,630720');
1 row(s) inserted.
INSERT INTO contain1(phone_number ,user_name ,address)
VALUES(9923421673,'KAVITHA','NO.560,allapy,kerala,360230');
1 row(s) inserted.
SELECT*FROM contain1;
WHERE phone_number=9923453452;
ADDRESS USER_NAME
NO.545,ram nagar,trichy,630720 POTHU
RESULT:
EX.NO : 16
Create a table to store the salary details of the employees in a company.
Declare the cursor to contain employee_number, employee_name and
DATE :
net_salary. Use cursor to update the employee salaries.
AIM:
PROCEDURE:
QUERIES:
Create table Employee:
Table created.
desc Employee51
EMPLOYEE5 EMPLOYEE_NU
Number - - 0 1 - - -
1 MBER
EMPLOYEE_NA
Varchar2 100 - - - - -
ME
NET_SALARY Number - - 0 - - -
1-3
VALUES(8072707504,'DHARMA',12000);
1 row(s) inserted.
VALUES(6323451232,'POTHU',19000);
1 row(s) inserted.
VALUES(6323519987,'KAVITHA',11000);
1 row(s) inserted.
SELECT*FROM Employee51;
UPDATE Employee51
SET net_salary=24000
WHERE Employee_name='DHARMA';
1 row(s) updated.
UPDATE Employee51
SET net_salary=25000
WHERE Employee_name='KAVITHA';
1 row(s) updated.
UPDATE Employee51
SET net_salary=30000
WHERE Employee_name='POTHU';
1 row(s) updated.
SELECT*FROM Employee51;
EX.NO : 17 Create a table to contain the information about the voters in a particular
constituency. Write a proper trigger to update or delete a row in the table.
DATE :
AIM:
PROCEDURE:
QUERIES:
Create table voters:
Table created.
desc voters
DATE_OF_BI
Varchar2 100 - - - - -
RTH
1-
5
VALUES('RAMESH','ABC162458','Male','07:01:2000','chennai');
1 row(s) inserted.
VALUES('PAVITHIRAN','ACB136279','Male','22:05:2002','trichy');
1 row(s) inserted.
VALUES('MADHAVAN','ADC749356','Male','03:06:2008','madurai');
1 row(s) inserted.
SELECT*FROM voters;
WHERE name='MADHAVAN';
1 row(s) deleted.
SELECT*FROM voters;
RESULT: