rag_dbms_file
rag_dbms_file
JMIT, RADAUR
Database Management System Lab
SESSION : 2022-2026
INDEX
Sr. Topic Date Remark
No
1. Write the queries for Data Definition Language (DDL) in
RDBMS.
2. Write the queries for Data Manipulation Language (DML)
in RDBMS.
For this purpose create a table with name , ssn , gross salary
and income tax of the employee.
13. Create trigger for before insertion or update.
14. Write SQL queries to make procedure to find area
of circle and insert in a table.
15. Write a program in PL/SQL using after update or
delete using Triggers.
Program 1:- Write the queries for Data Definition Language (DDL) in
RDBMS.
SQL> connect
system Connected.
SQL> create table RAGHAV(Name varchar2(20), RollNo number(10), Branch
1 row
created.
SQL> /
Enter value for name:
Ria Enter value for
rollno: 002 Enter value
for branch: IT
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values(Ria, '002',
'IT')
1 row
created.
SQL> /
Enter value for name:
Anu Enter value for
rollno: 003 Enter value
for branch: ME
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values('Anu',
'003', 'ME')
1 row
created.
SQL> /
Enter value for name:
Arun Enter value for
rollno: 004 Enter value
for branch: EE
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values('Arun', '004',
'EE')
1 row created.
SQL> /
Enter value for name:
Ram Enter value for
rollno: 005 Enter value
for branch: ECE
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values('Ram',
'005', 'ECE')
1 row created.
RAGHAV; Table
truncated.
1 row
created.
SQL> /
Enter value for name:
Siya Enter value for
rollno: 2 Enter value
for branch: IT
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values('Siya', '2',
'IT')
1 row
created.
SQL> /
Enter value for name:
Aditya Enter value for
rollno: 3 Enter value for
branch: EE
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values('Aditya',
'3', 'EE')
1 row
Subject Teacher Name: Er. Shilpa
JMIT, RADAUR
created.
SQL> /
Enter value for name:
Abhi Enter value for
rollno: 4 Enter value for
branch: ECE
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values('Abhi',
'4', 'ECE')
1 row created.
SQL> /
Enter value for name:
Pooja Enter value for
rollno: 5 Enter value for
branch: ME
old 1: insert into RAGHAV values('&Name', '&RollNo',
'&Branch') new 1: insert into RAGHAV values('Pooja',
'5', 'ME')
1 row created.
Program 3:- Write the queries for Data Control Language (DCL) in RDBMS
SQL> connect
system Connected.
SQL> create user Pual identified by
SQL> connect
Pual ERROR:
ORA-01045: user PUAL lacks CREATE SESSION privilege; logon denied
SQL> connect
Pual Connected.
SQL> select * from
tab; no rows
selected
SQL> connect
system Connected.
SQL> grant create table to
SQL> connect
Pual;
Connected.
SQL> create table RAGHAV (SNo
SQL> connect
system Connected.
SQL> revoke resource from
RAGHAV; Table
dropped.
SQL> create table RAGHAV (SNo number(3) constraint pri_k PRIMARY KEY, Name
RAGHAV; no rows
selected
Table altered.
SQL> drop table
RAGHAV; Table
dropped.
RAGHAV; Table
dropped.
1 row created.
SQL> /
Enter value for sno:
2 Enter value for
name: B
old 1: insert into RAGHAV values('&SNO',
'&Name') new 1: insert into RAGHAV
values('2', 'B')
1 row
created.
SQL> /
Enter value for sno:
3 Enter value for
name: C
old 1: insert into RAGHAV values('&SNO',
'&Name') new 1: insert into RAGHAV
values('3', 'C')
1 row
created.
SQL> /
Enter value for sno:
4 Enter value for
name: D
old 1: insert into RAGHAV values('&SNO',
'&Name') new 1: insert into RAGHAV
values('4', 'D')
1 row created.
Table created.
1 row
created.
SQL> /
Enter value for srno: 3
Enter value for
course: IT
old 1: insert into RAGHAV_child values('&SRNO',
'&Course') new 1: insert into RAGHAV_child
values('3', 'IT')
1 row
created.
SQL> /
Enter value for srno: 2
Enter value for course:
ME
old 1: insert into RAGHAV_child values('&SRNO',
'&Course') new 1: insert into RAGHAV_child
values('2', 'ME')
1 row created.
RAGHAV_child; Table
dropped.
Table
dropped.
SQL> spool
off
Table created.
1 row
created.
SQL> /
Enter value for empid: 2
Enter value for empname:
Rahul Enter value for salary:
1500 Enter value for bonus:
200
old 1: insert into RAGHAV
values('&EmpID','&EmpName','&Salary','&Bonus') new 1: insert into
RAGHAV values('2','Rahul','1500','200')
1 row
created.
SQL> /
Enter value for empid: 3
1 row created.
n SQL>
spool off
GENDER
femal
e
femal
e
male
femal
e
male
male
male
male
8 rows selected.
gender; GENDER
male
femal
e
EMPNAME||SALARY
Ajay1000
Rahul1500
Simran400
0
Program 6:- Write SQL query using character, number and group functions
SQL> select * from RAGHAV;
RAGHAV; CONCAT(ENAME,SALARY)
pavneet200
00
parul3000
RAGHAV; SUB
---
pa
v
par
RAGHAV; INSTR(ENAME,'V')
3
0
RAGHAV; RPAD(ENAME
pavneet
parul
LPAD(ENAME
pavneet
ENA
---
av
n
av
n
RAGHAV; UPPER(ENAME)
PAVNEET
PARUL
RAGHAV; ABS(SALARY)
20000
3000
RAGHAV; CEIL(SALARY)
20000
3000
RAGHAV; MOD(SALARY,DEPTNO)
32
39
RAGHAV; SIGN(SALARY)
1
1
SQRT(SALARY)
141.421356
54.7722558
RAGHAV; ADD_MONTH
13-JAN-17
13-JAN-17
RAGHAV; COUNT(*)
2
RAGHAV; EMPNO
102
101
RAGHAV; MAX(SALARY)
20000
RAGHAV; SUM(SALARY)
23000
1 Ram 20
2 Shyam 21
3 Ram 19
ROLLNO
1
2
3
NAME
Shyam
ROLL_NUMBER
1
2
3
ID NAME
1 Jack
2 Harry
3 Jackson
RAGHAV2; ID NAME
3 Jackson
4 Stephen
5 David
ID NAME
1 Jack
2 Harry
3 Jackson
4 Stephen
5 David
RAGHAV2; ID NAME
1 Jack
2 Harry
3 Jackson
3 Jackson
4 Stephen
5 David
6 rows selected.
ID NAME
3 Jackson
ID NAME
1 Jack
2 Harry
1 Ram 20
2 Shyam 21
3 Ram 19
2 Hindi Singing
3 English Dancing
4 English Writing
9 rows selected.
1 Ram Delhi
2 Varun Chd
3 Ravi Chd
4 Amrit Delhi
dept;
D1 HR 1
D2 IT 2
D3 MRKT 4
ENAME
Ram
Varu
n
Amrit
PROGRAM 8:- Write SQL queries for extracting data from more than one
table
SQL> select * from RAGHAV;
ROLLNO NAME AGE
1 Ram 20
2 Shyam 21
3 Ram 19
2 Hindi Singing
3 English Dancing
4 English Writing
1 Ram Delhi D1
2 Varun Chd D2
3 Ravi Chd D3
4 Amrit Delhi
D1 HR 1 Delhi
D2 IT 2 Pune
D3 MRKT 4
Patna
D4 Finance 5
Ram
Varu
n
ENAME
Ram
S1 C1 2016
S2 C2 2017
S1 C2 2017
S_ID
S1
S1
1 HARSH DELHI 18
2 PRATIK BIHAR 19
3 RIYANKA SILIGURI 20
4 DEEP RAMNAGAR 18
5 SAPTARHI KOLKATA 19
6 DHANRAJ BARABAJAR 20
7 ROHIT BALURGHAT 18
8 NIRAJ ALIPUR 19
8 rows selected.
COURSE_ID ROLL_NO
1 1
2 2
2 3
3 4
1 5
4 9
5 10
4 11
8 rows selected.
NAME COURSE_ID
HARSH 1
PRATIK 2
RIYANKA 2
DEEP 3
SAPTARHI 1
NIRAJ
DHANRAJ
ROHIT
8 rows selected.
HARSH 1
PRATIK 2
RIYANKA 2
DEEP 3
SAPTARHI 1
5
4
4
8 rows selected.
HARSH 1
PRATIK 2
RIYANKA 2
DEEP 3
SAPTARHI 1
NIRAJ
DHANRAJ
ROHIT
5
4
4
11 rows
selected. SQL>
Subject Teacher Name: Er. Shilpa
JMIT, RADAUR
spool off;
Program 9:- Write SQL queries for sub queries, nested queries
muskie 24 98776657 95
0 6
munni 237 85965634 76
5
pnni 251 98675645 77
3
nidhi 244 85857869 87
8
SQL> select * from RAGHAV where rollno in (select rollno from RAGHAV where
muskie 240 95
987766576
nidhi 244
58578698 87
Table created.
SQL> update RAGHAV set marks=marks-5 where rollno in(select rollno from
RAGHAV_bck where rollno>239);
3 rows updated.
SQL> delete from RAGHAV where rollno in (select rollno from RAGHAV_bck where
rollno>=240); 3 rows deleted.
SQL>spool off;
values('&name','&roll');
created.
SQL> /
roll: 1217216
SQL> /
1217637
created.
rahul 1217633
anshul 1217216
sahil 1217637
SQL> savepoint
a1; Savepoint
created.
values('ab','1717152');
1 row created.
Rollback complete.
RAGHAV;
NAME ROLL
rahul 1217633
anshul 1217216
sahil 1217637
Table created.
values('&rollno','&name','&branch','&marks');
for marks: 89
1 row
created.
SQL> /
values('&rollno','&name','&branch','&marks')
1 row created.
SQL> /
values('&rollno','&name','&branch','&marks')
1 row created.
1542 mohit IT 97
1 row created.
1542 mohit IT 97
empid: 1221
1 row created.
SQL> /
dept: IT
Subject Teacher Name: Er. Shilpa
JMIT, RADAUR
old 1: insert into emp1
1 row created.
SQL> /
CHEMICAL
created.
SQL> select*from
emp1; EMPID
DEPT
1221 CSE
1542 IT
1432 CHEMICAL
1542 mohit 97 IT
SQL> select*from
V; ROLLNO
NAME
1221 sejal
1542 mohit
1735 Vikas
1432 sahil
View created.
1221 sejal IT
View created.
NAME DEPT
sejal CSE
mohit IT
sahil CHEMICAL
For this purpose create a table with name , ssn , gross salary and income
tax of the employee.
SQL>create table RAGHAV(Name varchar2(20),GrossSalary
number(10),Tax_Percentage number(10));
Table Created.
gross number(10);
2 income(10);
3 begin
4 gross:=GrossSalary;
5 if gross<=40000 then
6 income:=0;
7 end if;
9 income:=10;
10 end if;
12 income:=20;
14 if gross>1000000 then
15 income:=30;
16 end if;
18 end
; 19 /
Procedure created.
SQL>EXECUTE Inc_CAL('Rahul',40000);
completed. SQL>EXECUTE
Inc_CAL('Shivam',60000);
completed. SQL>EXECUTE
Inc_CAL('Rajiv',80000);
RAGHAV;
Rahul 40000 0
Shivam 60000 10
Rajiv 80000 20
Table created.
values('pradeep','1207233','250');
1 row created.
values('rahul','1207239','195');
1 row created.
values('neeraj','1207215','400');
1 row created.
SQL> create or replace trigger tri before insert or update on RAGHAV for each row
2 begin
3 if :new.balance<=0 then
4 raise_application_error(-20000,'salary can not be less than zero');
5 end if;
6 end;
7/
Trigger created.
SQL> commit;
Commit
complete.
Program 14:- Write SQL queries to make procedure to find area of circle
and insert in a table.
SQL> create table RAGHAV(radius number(10),area
Procedure created.
SQL> execute
pro(7);
RAGHAV;
RADIUS AREA
7 154
RAGHAV;
RADIUS AREA
7 154
Subject Teacher Name: Er. Shilpa
JMIT, RADAUR
3 28
Program 15:- Write a program in PL/SQL using after update or delete using
Triggers.
SQL> create table RAGHAV_q11 (name varchar(10),salary
SQL> create trigger q31 after update or delete on RAGHAV_q11 for each row
2 declare
3 oper varchar(10);
4 name varchar(10);
5 salary number(10);
6 begin
7 if updating then oper:='update';
8 end if;
9 if deleting then oper:='delete';
10 end if;
11 name:=:old.name;
12 salary:=:old.salary;
13 insert into RAGHAV_q21 values(name,salary);
14 end;
15 /
Trigger created.
1 row
created.
SQL> /
Enter value for name:
Aman Enter value for
salary: 67000
Subject Teacher Name: Er. Shilpa
JMIT, RADAUR
old 1: insert into RAGHAV_q11
values('&name','&salary') new 1: insert into
RAGHAV_q11 values('Aman','67000')
1 row created.
NAME SALARY
Ashish 30000
Aman 67000
Aman 67000
Ashish 30000
Aman 80000
SQL>spool off;