RDBMS SEM 3 Practical Solutions
RDBMS SEM 3 Practical Solutions
com Page 1 of 8
Exercise – 1:
1. Create table EMP with columns emp_num, ename, sal and enter 10 records.
SQL>create table emp(emp_num number(3), ename varchar2(10),sal number(7,2));
Table created
Now inserting records into the emp table
SQL> insert into emp values(&emp_num,'&ename',&sal);
Enter value for emp_num : 101
Enter value for ename: waseem
Enter value for sal: 20000
old 1: insert into emp values(&emp_num,'&ename',&sal)
new 1: insert into emp values(101,'Raju',20000)
1 row created.
Press / enter to repeat the above statement to insert another record, repeat it for next 9 times,
after inserting the emp table is
10 rows selected.
Table altered.
After adding columns you need to update data for added columns to existing records in
emp table as shown below.
-Prepared by Mohammed Waseem Raza
Downloaded from: www.sucomputersforum.com Page 2 of 8
1 row updated.
By using above syntax format update remaining 9 records with distinct values.
10 Rows Selected.
3. Rename the Emp table with Employee and modify the ename column size as 20.
SQL> rename emp to employee;
Table renamed.
Table altered.
4. Display all the records from employee of dept_num 30
SQL>select * from employee where dept_num=30;
6. Drop the column dname and display details of employees whose salary greater than 15000.
SQL>alter table employee drop column dname;
Note: This query is not executing in our version.
ENAME SAL
---------- ---------
waseem 20000
anas 18000
shiva 18000
gangaram 17000
chandana 16000
raza 15000
sindhu 12000
sana 12000
bhargav 10000
rashmika 1200
5.
6. Display the names of employee in upper case.
Upper(ENAME)
-----------------------------
WASEEM
RAZA
SHIVA
GANGARAM
RASHMIKA
CHANDANA
SINDHU
BHARGAV
ANAS
SANA
lower(ENAME)
-----------------------------
waseem
raza
shiva
gangaram
rashmika
chandana
sindhu
bhargav
anas
sana
Exercise – 3:
1. Find the Dept which has maximum number of employee.
YEAR
-------
2017
3. Display the details of employees who are working for deptno 10 and 20.
SQL> select * from employee where dept_num in(10,20);
EMP_NUM ENAME SAL DNAME DEPT_NUMLocation DOJ JOB
--------- ---------- --------- ----------------- --------------- ------------------ ------------------ ------------------
101 waseem 20000 ACCOUNTS 10 HYD 01-MAR-20 CLERK
102 raza 15000 SALES 20 PUNE 05-AUG-15 SOFTWARE
104 gangaram 17000 ACCOUNTS 10 HYD 01-APR-20 CLERK
105 rashmika 1200 SALES 20 PUNE 01-NOV-20 SOFTWARE
107 sindhu 12000 ACCOUNTS 10 HYD 01-JAN-21 CLERK
108 bhargav 10000 SALES 20 PUNE 05-FEB-21 SOFTWARE
4. Update the HRA=15%, DA=10%, TA=10% for all the Employees whose is experience more
than 10 years.
Before update HRA,DA and TA we have to add three columns and update those values to
employee table.
Adding three columns:
Table altered.
SQL> update employee set HRA=sal*0.15,DA=sal*0.1,TA=sal*0.1 where
(months_between(sysdate,doj)/12)>10;
No rows selected
5. Write a query to delete duplicate records from emp.
SQL> delete from employee where emp_num=(select emp_num from employee group by emp_num
having count(*)>1);
0 rows deleted.
-Prepared by Mohammed Waseem Raza
Downloaded from: www.sucomputersforum.com Page 7 of 8
DEPT_NUM SUM(SAL)
--------- ---------
10 49000
20 26200
30 30000
40 34000
Exercise – 4:
1. Make the duplicate table as emp12 on emp
Table created.
2. Add Constraint Primary Key for emp_num and dept_num columns for emp table
Table altered.
3. Remove the referential integrity from employee table and dept table.
Table altered.
4. Display the name of Employees who earn the Highest salary in their respective
departments.
SQL> select ename from employee where (dept_num,sal) in(select dept_num,max(sal) from
employee group by dept_num);
ENAME
--------------
waseem
raza
shiva
anas
no rows selected
Exercise – 5:
1. Display all rows from Emp Table. The System wait after every Screen full of information.
SQL> set pause on;
SQL> select emp_num,ename,sal from employee;
If you want to see the output of selected columns from employees press enter key then it display
selected columns
EMP_NUM ENAME SAL
--------- ---------- ---------
101 waseem 20000
102 raza 15000
103 shiva 18000
104 gangaram 17000
105 rashmika 1200
106 chandana 16000
107 sindhu 12000
108 bhargav 10000
109 anas 18000
110 sana 12000
View created.
3. Create a view for emp table where deptno=10.
SQL> create view v2 as select * from employee where dept_num=10;
View created.
4. Drop table the view of emp table.
SQL> drop view v1;
View dropped.
5. Delete all the records from the emp where the deptname is NULL.
SQL> delete from employee where dname is null;
0 rows deleted.
6. Delete the rows of employees whose experience is less than 5 year.
SQL> delete from employee where ((months_between(sysdate,doj))/12)<5;
10 rows deleted.