R.D.B.M.S Practical Lab Record
R.D.B.M.S Practical Lab Record
RDBMS-SQL LAB
SQL>create table Supplier(Sup_No varchar2(3) PRIMARY KEY, Sup_Name varchar2(10), Item_Supplied varchar2(10),
Item_Price number(6), City varchar2(12));
Table created.
SQL>desc Supplier;
1. Write sql query to display Suplier numbers and Supplier names whose name starts with ‘R’
2. Write sql query to display the name of suppliers who supply Processors and whose city is Delhi.
3. Write sql query to display the names of suppliers who supply the same items as supplied by Ramesh.
selectSup_Name from Supplier where Item_Supplied in (select Item_Supplied from Supplier where
Sup_Name='Ramesh');
2
B.Com.II Year III Sem. RDBMS-SQL LAB
5. Write sql query to display supplier numbers, Suplier names and itemprice for suppliers in delhi in the ascending order
of itemprice.
Table alterd.
desc Supplier;
7. Write sql query to delete the record whose itemprice is the lowest of all the items supplied .
1 row(s) deleted.
3
B.Com.II Year III Sem. RDBMS-SQL LAB
8. Create a view on the table which displays only supplier numbers and supplier names.
view created.
9. Write sql query to display the records in the descending order of itemprice for each itemsupplied.
select * from Supplier order by Item_Pricedesc;
10. Write sql query to display the records of suppliers who supply items other than Processor or Keyboard.
select * from Supplier where Item_Supplied not in( select Item_Supplied from Supplier where Item_Supplied='Processor'
or Item_Supplied='Keyboard');
4
B.Com.II Year III Sem. RDBMS-SQL LAB
B. Below are the details of Employees working for a software Company. (For questions from 11 to 20) Create
the table called EmpDetailswith the below mentioned details.
create table EmpDetails(Eid varchar2(5) PRIMARY KEY, Ename varchar2(10), DOB date, Designation varchar2(10), Salary
number(8), DOJ date);
Table created.
descEmpDetailsB
5
B.Com.II Year III Sem. RDBMS-SQL LAB
11. Write sql query to display all the employees whose designation is Programmer.
12. Write sql query to display employees who have joined after 2014.
13. Write sql query to display all the employees whose name ends with ‘a’.
select * from EmpDetailsB where Ename like '%a';
6
B.Com.II Year III Sem. RDBMS-SQL LAB
14. Write sql query to display the total salary of all the employees whose designation is programmer.
15. Write sql query to display all the employee names in upper case.
16. Write sql query to display the details of the employee with highest experience.
17. Write sql query to display the details of the employees whose name contains ‘ee’.
7
B.Com.II Year III Sem. RDBMS-SQL LAB
18. Write sql query to increase the salaries of employees by 5000 whose designation is DBA.
2 Row(s) updated.
19. Write sql query to display the employees whose salary is more than the average salary of all the employees.
20. Write sql query to display the record in the following format: xxxxxxxxx is working as xxxxxxxxxxxxxx with a Salary of
Rs.xxxxxxxx
eg: Suma is working as Designer with a Salary of Rs. 20000
selectEname, 'is working as ', Designation, 'with Salary of Rs.', Salary from EmpDetailsB;
8
B.Com.II Year III Sem. RDBMS-SQL LAB
C. Create the two tables as shown below with the given constraints: (for questions 21 to 30)
Table name: Employee Tablename: Department
Constraints: Eid is Primary key and DeptId is foreign key Constraints:DeptId Primary key
Salary should not be less than 10000 and Dname is NOT NULL
IN ORDER TO ESTABLISH FOREIGN KEY, WE HAVE TO CREATE DEPARTMENT TABLE FIRST AND THEN USE THE DeptId
COLUMN IN THE Employee TABLE.
Table created.
desc Department;
9
B.Com.II Year III Sem. RDBMS-SQL LAB
create table Employee(Eid varchar2(5) PRIMARY KEY, Ename varchar2(20),DeptId varchar2(10) NOT NULL,Designation
varchar2(20),Salary number(8) check(salary>10000), DOJ date, FOREIGN KEY(DeptId)REFERENCES Department(DeptId));
desc Employee;
10
B.Com.II Year III Sem. RDBMS-SQL LAB
21. Write sql query to display all the employees who earn more than average salary of all the employees in the
company.
22. Write sql query to display the fields Eid, Ename and Dname.
23. Write sql query to sort the employee table in the descending order of salaries.
11
B.Com.II Year III Sem. RDBMS-SQL LAB
24. Write sql query to list all the job designations in the employee table without repetitions.
25. Write sql query to display all the employee details Department wise and in the ascending order of their salaries.
selectd.DeptId,d.Dname, e.Eid, e.Ename, e.Salary from Employee e, Department d where d.DeptId=e.DeptId order by
DeptId, Salary;
26. Write sql query to display all the clerks in DeptId D2.
12
B.Com.II Year III Sem. RDBMS-SQL LAB
27. Write sql query to display all the employees who joined in the year 2011.
select * from Employee where DOJ>='01-Jan-2011' and DOJ<='31-Dec-2011';
28. Write sql query to display all the employees who joined in the month of February.
29. Write sql query to display all the employees whose salary is between 30000 and 45000.
select * from Employee where Salary between 30000 and 45000;
30. Write sql query to display all the employee details along with their work experience in the company till current date.
select Eid, Ename, DeptId,Designation, Salary, DOJ,round((sysdate-DOJ )/365) as Experience from Employee;
13
B.Com.II Year III Sem. RDBMS-SQL LAB
D. Below are the details of Students enrolled in various course of B.Com (For questions from 31 to 40)
Create the table called Student with the below mentioned details.
create table Student (Sid varchar(10)Primary Key,Snamevarchar2(20) NOT NULL, DOB date NOT NULL, State char(20)
NOT NULL, Gender char(1) NOT NULL, Category char(20) NOT NULL, Course char(20) NOT NULL);
Table created.
desc student;
INSERT INTO Student values(1001, 'Neha', '29-Dec-02', 'Telangana', 'F', 'Gen', 'Comp');
14
B.Com.II Year III Sem. RDBMS-SQL LAB
INSERT INTO Student values(1002, 'Arun', '10-Jan-02', 'Telangana', 'M', 'OBC', 'Honors');
INSERT INTO Student values(1003, 'Payal', '15-Aug-01', 'Maharashtra', 'F', 'Gen', 'Appl');
INSERT INTO Student values(1004, 'Amrita', '20-Apr-02', 'Karnataka', 'F', 'OBC', 'Honors');
INSERT INTO Student values(1005, 'Pavan', '29-May-03', 'AndhraPradesh', 'M', 'ExServicemen', 'Comp');
INSERT INTO Student values(1006, 'Anchal', '1-May-03', 'Gujarat', 'F', 'OBC', 'Comp');
INSERT INTO Student values(1007, 'Ramya', '13-Jan-02', 'Telangana', 'F', 'Gen', 'Appl');
INSERT INTO Student values(1008, 'Rakesh', '22-Dec-01', 'AndhraPradesh', 'M', 'Sports', 'Comp');
31. Write sql query to display the students who are not from Telangana or AndhraPradesh.
32. Create a view to display the columns Sid, Sname for students belonging to Telangana.
create view SIdName as select Sid, Sname from Student where state='Telangana';
View created
15
B.Com.II Year III Sem. RDBMS-SQL LAB
desciSname;
34. Write sql query to display all the female students enrolled under Comp course and who belong to OBC.
select * from Student where Course='Comp' and Gender='F' and Category='OBC';
35. Write sql query to display the student ids, names, and their present age.
36. Write sql query to display the students in the ascending order of their names for each course.
16
B.Com.II Year III Sem. RDBMS-SQL LAB
37. Write sql query to delete all the students records who have enrolled for Comp course and who are born after 2002.
2 Row(s) deleted.
38. Write a sql query to add two new columns Contactno and Email to the existing fields.
Table altered.
Desc Student;
17
B.Com.II Year III Sem. RDBMS-SQL LAB
39. Write an sql query to display all the Student names prefixed with Mr./Ms. Based on Gender column.
Select
Sname,case
end as NamewithTitlePrefix
from student;
40. Write ansql query to display all the Student names where the length of the name is 5 characters.
18
B.Com.II Year III Sem. RDBMS-SQL LAB
create table Library(BookId varchar2(10) primary key,BookName varchar2(20) not null,Author varchar2(20)
,DatePurchaseddate,Publisher varchar2(20),price number(7));
Table created.
desc Library;
19
B.Com.II Year III Sem. RDBMS-SQL LAB
41. Write sql query to display the list of authors from Himalaya publications.
42. Write sql query to display the total cost of books purchased Publisher wise.
43. Write sql query to count the total number of books under Kalyani publications.
select publisher, count(*) as NoOfBooks from Library where Publisher='Kalyani' group by publisher;
20
B.Com.II Year III Sem. RDBMS-SQL LAB
Table Altered.
desc Library;
45. Write a sql query to display the books in the ascending order of DatePurchased.
46. Write sql query to create an index on the fields BookName and Author.
47. Write sql query to display the books whose price is between 500 and 700
selectBookName, Price from Library where Price BETWEEN 500 and 700;
21
B.Com.II Year III Sem. RDBMS-SQL LAB
48. Write sql query to increase the price of all the books by 200 for publishers other than Himalaya or Kalyani.
ALTER THE PUBLICATION COLUMN TO PUBLISHER AND THEN UPDATE THE TABLE.
Table Altered.
desc Library1;
2 row(s) updated.
49. Write sql query to display the book details where author name contains the name Sharma.
1 row returned
50. Create a view to display the fields BookId and BookName where the Publisher is Himalaya.
create view BookIdNameView as select BookId, BookName from Library where publisher='Himalaya';
View created
22