RDBMS Lab Record 2021-II BCA
RDBMS Lab Record 2021-II BCA
VISWA MAHAVIDYALAYA
(UNIVERSITY ESTABLISHED under section 3 of UGC Act 1956)
RDBMS Lab
LABORATORY RECORD
Name : ______________________________________
Reg. No : _ __________
BONAFIDE CERTIFICATE
II Year B.C.A in the RDBMS Lab during the year November 2021
Page
S.No Date Title Signature
No
AIM:
Write a SOL program for data definition language commands in RDBMS.
Algorithm:
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:
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:
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:
Program:
Select
select * from emp where id in(select id from emp where salary >15000);
1 balaji 25000
2 dinesh 18000
Insert
insert into emp1 select * from emp where id in (select id from emp);
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;
Delete
delete from empid where id in (select empid from emp where empid >1);
Result:
Thus the sub query commands are successfully executed.
6
SQL JOIN
AIM:
Write a SQL program for SQL join commands in RDBMS.
Algorithm:
Program
select * from emp;
Inner join
Syntax :
Example:
select * from emp inner join emp1 using(empid,empname);
7
EMPID EMPNAME SALARY DEPT ADDRESS PHONE
Left join
Example:
select * from emp left join emp1 using(empid,empname);
Right join
Example:
Full join
Example:
select * from emp full join emp1 using(empid,empname);
8
EMPID EMPNAME SALARY DEPT ADDRESS PHONE
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:
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
10
Output
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
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
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;
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;
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