0% found this document useful (0 votes)
24 views

RDBMS Lab Record 2021-II BCA

This document is a laboratory record for the RDBMS Lab at Sri Chandrasekharendra Saraswathi Viswa Mahavidyalaya, detailing various SQL and PL/SQL programs related to database management. It includes a bonafide certificate, an index of exercises, and specific examples of Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), sub-queries, and SQL joins. The document serves as a practical guide for students in the II Year B.C.A program to demonstrate their understanding and application of RDBMS concepts.
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)
24 views

RDBMS Lab Record 2021-II BCA

This document is a laboratory record for the RDBMS Lab at Sri Chandrasekharendra Saraswathi Viswa Mahavidyalaya, detailing various SQL and PL/SQL programs related to database management. It includes a bonafide certificate, an index of exercises, and specific examples of Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), sub-queries, and SQL joins. The document serves as a practical guide for students in the II Year B.C.A program to demonstrate their understanding and application of RDBMS concepts.
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
You are on page 1/ 24

SRI CHANDRASEKHARENDRA SARASWATHI

VISWA MAHAVIDYALAYA
(UNIVERSITY ESTABLISHED under section 3 of UGC Act 1956)

ENATHUR, KANCHIPURAM – 631 561

Department of Computer Science and Applications

RDBMS Lab

LABORATORY RECORD

Name : ______________________________________

Reg. No : _ __________

Class : II Year B.C.A

Subject : CC307– RDBMS Lab


SRI CHANDRASEKHARENDRA SARASWATHI
VISWA MAHAVIDYALAYA
(University Established under section 3 of UGC Act 1956)

BONAFIDE CERTIFICATE

This is to Certify that this is the bonafide record of work done by

Mr./Ms._______________________________________, with Reg.No._ __ of

II Year B.C.A in the RDBMS Lab during the year November 2021

Staff-in-charge Head of the Department


Dr. C. Parthasarathy (Dr. T. Nirmal Raj)
Asst. Professor, Asst. Professor,
Department of Computer Science Department of Computer Science
and Applications. and Applications.

Submitted for the Practical Examination held on 16-11-2021_

Internal Examiner External Examiner


INDEX

Page
S.No Date Title Signature
No

Data Definition Language (DDL) Commands in


1 14/08/21 1
RDBMS

Data Manipulation Language (DML)and Data Control


2 28/08/21 Language (DCL)Commands in RDBMS Sub-queries and 3
JOIN

PL/SQL Program for inserting record into employee


3 04/09/21 10
table

PL/SQL Program for selecting records from employee


4 11/09/21 12
table whose name begin with ‘a’

PL/SQL Block to generate EVEN ODD number less


5 18/09/21 13
then n using any looping statement

PL/SQL Program to display employee name from


6 25/09/21 employee table whose Who are in deptno 10 using 15
cursor

PL/SQL Program to Raise an Application Error when the


09/10/21
7 Employee Salary is Greater than 3000 using Employee 16
table

PL/SQL Program to copy the content of one table to


8 16/10/21 18
another table

PL/SQL Program to find the biggest of two numbers


9 23/10/21 20
using function
1. Data Definition Language (DDL) Commands in RDBMS

AIM:
Write a SOL program for data definition language commands in RDBMS.

Algorithm:

Step 1: start a program


Step 2: write a commands are
Step 3: create, alter, drop, truncate, rename
Step 4: stop program

Program:

Create Table
Syntax
create table tablename(fieldname 1 datatype(size)….);
Example:
create table employee(empid varchar(10),name varchar(10),salary varchar(10) );

Alter Table:
I. Add
II. Modify
I. Add
Syntax:
alter table tablename add(fieldname datatype(size)…);
Example:
alter table employee add(dept varchar(15));

II. Modify
Syntax:
alter table tablename modify(fieldname datatype(size));
Example:
alter table employee modify(salary varchar(15));

1
Rename
Syntax:
rename table tablename to new tablename;
Example:
rename employee to employeeinfo;

Truncate
Syntax:
truncate table tablename;
Example:
truncate table emp;

Drop table
Syntax:
drop table tablename;
Example:
drop table employee;

Result:
Thus the DDL commands are successfully executed.

2
2. Data Manipulation Language (DML) and Data Control Language

AIM:
Write a SQL program for data manipulation language commands in RDMBS.

Algorithm:

Step 1: start a program


Step 2: write a commands are
Step 3: insert, update, delete, select
Step 4: stop the program

Program :
Insert
Syntax:
insert into table name values(value1,value2….);

Example:
insert into employee values(1,’balaji’,25000);
Update
Syntax:
update tablename set (attribute)=(expression) where (condition);
Example:
update employee set name=’dinesh’ where empid=1;
Delete
Syntax:
delete from tablename where condition;

Example:
delete from employee where empid=2;

Select
Syntax:
select * from tablename;

Example:
Select * from employee;

Result:
Thus the DML commands are successfully executed.

3
Data Control Language (DCL)
AIM:
Write a SQL program for data control language commands in RDBMS.

Algorithm:

Step 1: start a program


Step 2: write a commands are
Step 3: grant, revoke
Step 4: stop program

Program:
1.Grant
2.Revoke
Grant
Syntax:
grant privilagename on objectname to username;
Example
grant all on worker to system;

Revoke
Syntax :
revoke privilagename on viewname from username;
Example:
revoke update on worker from system;

Result:
Thus the DCL commands are successfully executed.

4
Sub Query
AIM:
Write a SQL program for sub query commands in RDBMS.

Algorithm:

Step 1: start a program


Step 2: write a commands are
Step 3: select, insert, update, delete
Step 4: stop program

Program:

Select

select * from emp where id in(select id from emp where salary >15000);

EMPID NAME SALARY

1 balaji 25000
2 dinesh 18000

Insert

insert into emp1 select * from emp where id in (select id from emp);

EMPID NAME SALARY

1 balaji 25000
2 dinesh 18000

Update
update emp set salary=salary+salary*0.15 where salary in (select salary from emp where
salary>15000);

5
select * from emp;

EMPID NAME SALARY


-
1 balaji 28750
2 dinesh 20700

Delete

delete from empid where id in (select empid from emp where empid >1);

select * from emp;

EMPID NAME SALARY


-
1 balaji 25000

Result:
Thus the sub query commands are successfully executed.

6
SQL JOIN
AIM:
Write a SQL program for SQL join commands in RDBMS.

Algorithm:

Step 1: start a program


Step 2: write a commands are
Step 3: inner join, left join, right join, and full join
Step 4: stop program

Program
select * from emp;

EMPID EMPNAME SALARY DEPT


-
1 balaji 15222 cs
2 prakesh 10000 mech
3 selvam 10100 eee

select * from emp1;

EMPID EMPNAME ADDRESS PHONE


-
1 balaji kpm 9715782883
3 selvam ms 7715782883

Inner join

Syntax :

select column name from tablename1 inner join tablename2 using(filedname..);

Example:
select * from emp inner join emp1 using(empid,empname);

7
EMPID EMPNAME SALARY DEPT ADDRESS PHONE

1 balaji 15222 cs kpm 9715782883


3 selvam 10100 eee ms 7715782883

Left join

select column name from tablename1 left join tablename2 using(filedname..);

Example:
select * from emp left join emp1 using(empid,empname);

EMPID EMPNAME SALARY DEPT ADDRESS PHONE

1 balaji 15222 cs kpm 9715782883


3 selvam 10100 eee ms 7715782883
2 prakesh 10000 mech

Right join

select column name from tablename1 right join tablename2 using(filedname);

Example:

select * from emp right join emp1 using(empid,empname);

EMPID EMPNAME SALARY DEPT ADDRESS PHONE

1 balaji 15222 cs kpm 9715782883


3 selvam 10100 eee ms 7715782883

Full join

select column name from tablename1 full join tablename2 using(filedname..);

Example:
select * from emp full join emp1 using(empid,empname);

8
EMPID EMPNAME SALARY DEPT ADDRESS PHONE

1 balaji 15222 cs kpm 9715782883


3 selvam 10100 eee ms 7715782883
2 prakesh 10000 mech

Result:
Thus the SQL join commands are successfully executed .

9
3. PL/SQL Program for inserting record into employee table

AIM:
Write a PL/SQL program for inserting record into employee table

Algorithm:

Step 1: start the program


Step 2: create table emp (empid varchar(10),empname varchar(15), gender
varchar(6),dept varchar(10),salary varchar(10));
Step 3: table created successfully
Step 4: stop the program

Program:
declare
empid varchar(10):=&empid;
empname varchar(10):=&empname;
gender varchar(10):=&gender;
dept varchar(10):=&dept;
salary varchar(10):=&salary;
Begin
Insert into emp values(&empid,&empname,&gender,&dept,&salary);
end;
/
Enter value for empid:1
Enter value for empname:’ram’
Enter value for gender:’male’
Enter value for dept:’cs’
Enter value for salary:150000

PL/SQL procedure successfully completed.

10
Output

SQL> select * from emp;

EMPID EMPNAME GENDER DEPTNO SALARY

1 balaji male cs 150000

Result
Thus the program PL/SQL inserts the employee record successfully

11
4. PL/SQL Program for selecting records from employee table
whose name begin with ‘a’
AIM:
Write a PL/SQL program for select record from employee table whose name begin with a

Algorithm:
Step 1: start the program
Step 2: insert the values from employee table empname with start with a name
Step 3: using insert command and insert the value
Step 4: stop the program

Program:
declare
cursor empdata is(select * from emp where name like 'a%' or name like 'A%');
x emp % rowtype;
begin
open empdata;
loop
fetch empdata into x;
exit when empdata %notfound;
dbms_output.put_line(x.name||','||x.id||','||x.salary);
end loop;
close empdata;
end;
/

Output:

aijth,1,15000
ashok,3,19000
PL/SQL procedure successfully completed.

Result:
Thus the program PL/SQL program for select record from employee table whose name
begin with ‘a’ successfully executed

12
5. PL/SQL Program for block to generate Even Odd number less
then N using any one loop
AIM:
Write a PL/SQL program for block to generate even and number less then n using any
one loop

Algorithm:
Step 1: start the program
Step 2: declare the n variable
Step 3: using for loop and if condition
Step 4: if condition is true then print even number
Step 5: condition false then print odd number
Step 6: stop the program

Program:
declare
n number;
begin
n:=&n;
for i in 1..n loop
if mod (i,2)=0 then
dbms_output.put_line(i ||’ is even number’);
else
dbms_output.put_line(i ||’ is odd number’);
end if;
end loop;
end;
/
Enter value for n: 5
old 5: n:=&n;
new 5: n:=5;

Output :
PL/SQL procedure successfully completed.

13
SQL> set serveroutput on
SQL> /
Enter value for n: 5
old 4: n:=&n;
new 4: n:=5;
1 is odd number
2 is even number
3 is odd number
4 is even number
5 is odd number

PL/SQL procedure successfully completed.

Result:
Thus the PL/SQL program for block to generate even and number less then n using any
one loop successfully executed

14
6. PL/SQL display employee name from employee table whose are in
deptno. 10 using cursor
AIM:
Write a PL/SQL display employee name from employee table whose are in deptno. 10
using cursor

Algorithm:
Step 1: start the program
Step 2: create table emp (empid varchar(10),empname varchar(15), gender
varchar(6),deptno varchar(10),salary varchar(10));
Step 3: insert the records
Step 4: using cursor create the cursor name declare the select statement
Step 5: open the cursor and fetch the records
Step 6: print the values
Step 7: close the cursor
Step 8: stop the program

Program:
declare
cursor empdept is(select * from emp where deptno =10);
x emp %rowtype;
begin
open empdept;
loop
fetch empdept into x;
exit when empdept %notfound;
dbms_output.put_line(x.name||','||x.id||','||x.deptno||','||x.salary);
end loop;
close empdept;
end;
/
Output :
balaji,1,10,54000
dinesh,5,10,53000

PL/SQL procedure successfully completed.

Result:
Thus the program PL/SQL display employee name from employee table whose are in
deptno. 10 using cursor successfully executed

15
7. PL/SQL program to raise an application error when the employee
salary is greater than 3000 using employee table

AIM:
Write a PL/SQL program to raise an application error when the employee salary is greater
than 3000 using employee table

Algorithm:
Step 1: start the program
Step 2: create table emp (empid varchar(10),empname varchar(15),
gender varchar(10),deptno varchar(10),salary varchar(10));
Step 3: insert the records
Step 4: declare the two variable salary and no in the employee table
Step 5: using select statement
Step 6: using the if condition greater than 3000 condition is true then
raise on the error
Step 7: condition 3000 below is update the salary
Step 8: close the if condition
Step 9: exception occur the no employee values
Step10: stop the program

Program:
declare
salary emp.empsalary %type;
no emp.empid %type;
begin
no:=&no;
select empsalary into salary from emp where empid=no;
if salary >3000 then
Raise_application_error(-20300,’high-salary’);
else
update emp set empsalary=empsalary+empsalary*0.1where empid=no;
end if;
exception
when no_data_found then
dbms_output.put_line(no||’is in valid employee number’);
end;
/

16
Enter value for n: 1
old 5: no:=&n;
new 5: no:=1;
PL/SQL procedure successfully completed.

Output:
Select * from emp;

EMPID NAME SALARY

1 balaji 1650
2 dinesh 1700

Result :
Thus the program PL/SQL program to raise an application error when the employee salary is
greater than 3000 using employee table successfully executed

17
8. PLSQL program copy the content of one table to another table

AIM:
Write the program PL/SQL program copy the content of one table to another table

Algorithm:
Step 1: start the program
Step 2: create the 2 table
Step 3: create table emp (empid varchar(10),empname varchar(15),
gender varchar(10),deptno varchar(10),salary varchar(10));
Step 4: insert the emp table only the records
Step 5: create table emp1 (empid varchar(10),empname varchar(15),
gender varchar(10),deptno varchar(10),salary varchar(10));
Step 6: using cursor create the cursor name declare the select statement
Step 7: open the cursor and fetch the records
Step 8: copy the table from emp1
Step 9: close the cursor
Step 10: stop the program

Program:
declare
cursor data is(select * from employee);
x employee %rowtype;
begin
open data;
loop
fetch data into x;
exit when data %notfound;
insert into emp1 values(x.empid,x.empname,x.deptno,x.salary);
end loop;
close data;
end;
/

Output :
PL/SQL procedure successfully completed.

18
SQL> select * from emp1;

EMPID EMPNAME SALARY


1 balaji 150000
2 dinesh 130000

Result:
Write the program PL/SQL program copy the content of one table to another table
successfully executed

19
9. PL/SQL Program to find the Biggest of two number using
Function.
Aim:
Write the PL/SQL Program to find the Biggest of two number using Function.

Algorithm:
Step 1: start the program
Step 2: declare the three variable a,b,c
Step 3: using the function pass the argument x and y
Step 4: using the if condition x> y and y>x condition is true then x or y is greater then
Step 5: else is z is greater then
Step 6: close the if condition
Step 7: close the function and return the value
Step 8: value pass the function
Step 9: print the value
Step 10: stop the program

Program:
declare
a number;
b number;
c number;
function find(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:=find(a,b);
dbms_output.put_line('maximum of (23,45):'||c);
end;
/

20
Output :
SQL> set serveroutput on
SQL> /
maximum of (23,45):45
PL/SQL procedure successfully completed.

Result:
Thus PL/SQL Program to find the Biggest of two number using function
Successfully executed

21

You might also like