Professional Documents
Culture Documents
RDBMS Lab Record-1
RDBMS Lab Record-1
Table created.
SUP_NAME VARCHAR2(20)
ITEM_SUPPLIED VARCHAR2(20)
ITEM_PRICE NUMBER(6,2)
CITY VARCHAR2(20)
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
6 rows selected.
I. Queries on Supplier Table
1. Write sql query to display Suplier numbers and Supplier names whose name starts with ‘R’
SQL> SELECT SUP_NO, SUP_NAME FROM SUPPLIER WHERE SUP_NAME LIKE 'R%';
SUP_NO SUP_NAME
-- --------------------------------
S4 Ramesh
2. Write sql query to display the name of suppliers who supply Processors and whose city is
Delhi.
SUP_NAME
--------------------
Kiran
3. Write sql query to display the names of suppliers who supply the same items as supplied
by Ramesh.
SUP_NAME
--------------------
Kiran
Ramesh
ITEM_SUPPLIED ITEM_PRICE
-------------------- ----------
Keyboard 600
5. Write sql query to display supplier numbers, Suplier names and itemprice for suppliers in
delhi in the ascending order of itemprice.
7. Write sql query to delete the record whose itemprice is the lowest of all the items
supplied.
MIN(ITEM_PRICE)
---------------
350
SQL> DELETE FROM SUPPLIER WHERE ITEM_PRICE = (SELECT MIN(ITEM_PRICE) FROM
SUPPLIER);
1 row deleted.
5 rows selected.
8. Create a view on the table which displays only supplier numbers and supplier names.
SQL> CREATE VIEW SUP_NO_NAME AS SELECT SUP_NO, SUP_NAME FROM SUPPLIER;
View created.
SUP_ NO SUP_NAME
-- --------------------
S1 Suresh
S2 Kiran
S3 Mohan
S4 Ramesh
S5 Manish
S6 Srikanth
6 rows selected.
9. Write sql query to display the records in the descending order of itemprice for each
itemsupplied.
ITEM_SUPPLIED ITEM_PRICE
-------------------- --------------------------------------------------
Processor 9000
Processor 8500
Processor 8000
Printer 6000
Keyboard 600
Mouse 350
6 rows selected.
10. Write sql query to display the records of suppliers who supply items other than Processor
or Keyboard.
Table created.
SQL> /
Enter value for eid: E102
Enter value for ename: Amit
Enter value for dob: 10-Jan-95
Enter value for designation: Programmer
Enter value for salary: 25000
Enter value for doj: 18-Feb-18
old 1: INSERT INTO EMPDETAILS
VALUES('&EID','&ENAME','&DOB','&DESIGNATION','&SALARY','&DOJ')
new 1: INSERT INTO EMPDETAILS VALUES('E102','Amit','10-Jan-
95','Programmer','25000','18-Feb-18')
1 row created.
Below are the details of Employees working for a software Company
7 rows selected.
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.
14. Write sql query to display the total salary of all the employees whose designation is
programmer.
TOTAL_SALARY
------------
110000
15. Write sql query to display all the employee names in upper case.
UPPER(ENAME)
--------------------
SUMA
AMIT
PAYAL
KIRAN
MEENAL
SHEILA
SWAMY
SUSHMA
8 rows selected.
16. Write sql query to display the details of the employee with highest experience
SQL> SELECT * FROM EMPDETAILS WHERE DOJ = (SELECT MIN(DOJ) FROM EMPDETAILS);
17. Write sql query to display the details of the employees whose name contains‘ee’.
18. Write sql query to increase the salaries of employees by 5000 whose designation is DBA
SQL> UPDATE EMPDETAILS SET SALARY = SALARY + 5000 WHERE DESIGNATION = 'DBA';
2 rows updated.
AVG(SALARY)
-----------
41250
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
isforeign key Constraints:DeptId Primary key and Dname is NOT NULL
DEPRTMENT TABLE
EMPLOYEE TABLE
CREATE TABLE EMPLOYEE(EID NUBMER(3) PRIMARY KEY, ENAME VARCHAR2(20), DEPTID
CHAR(2) REFERENCES DEPARTMENT, DESIGNATION VARCHAR2(20), SALARY NUMBER(7,2),
DOJ DATE);
Table created.
ENAME VARCHAR2(20)
DEPTID CHAR(2)
DESIGNATION VARCHAR2(20)
SALARY NUMBER(7,2)
DOJ DATE
DE
PTID DNAME
-- --------------------
D1 Sales
D2 Marketing
D3 Finance
20. Write sql query to display all the employees who earn more than average salary of all the
employees in the company
SQL> SELECT * FROM EMPLOYEE WHERE SALARY>( SELECT AVG(SALARY) FROM EMPLOY
EE);
21. Write sql query to display the fields Eid, Ename and Dname
SQL> SELECT EID, ENAME, DNAME FROM EMPLOYEE E, DEPARTMENT D WHERE E.DEPTID =
D.DEPTID;
8 rows selected.
22. Write sql query to sort the employee table in the descending order ofsalaries.
8 rows selected.
23. Write sql query to list all the job designations in the employee table without repetitions
--------------------
Clerk
Manager
Salesman
24. Write sql query to display all the employee details Department wise and in the ascending
order of their salaries.
8 rows selected.
25. Write sql query to display all the clerks in DeptId D2.
27. Write sql query to display all the employees who joined in the month of February
28. Write sql query to display all the employees whose salary is between 30000 and 45000.
SQL> SELECT * FROM EMPLOYEE WHERE SALARY BETWEEN 30000 AND 45000;
8 rows selected.
D. Create the table called Student with the below mentioned details. (For questions from 31
to 40)
Table created.
6 rows selected.
30. Write sql query to display the students who are not from Telangana or AndhraPradesh.
31. Create a view to display the columns Sid, Sname for students belonging to Telangana.
View created.
SID SNAME
---------- -----------
1001 Neha
1002 Arun
1007 Ramya
Index created.
33. Write sql query to display all the female students enrolled under Comp course and who
belong to OBC
34. Write sql query to display the student ids, names, and their present age
SQL> SELECT SID, SNAME, EXTRACT(YEAR FROM SYSDATE)-EXTRACT(YEAR FROM DOB) AS
AGE FROM STUDENT;
1001 Neha 20
1002 Arun 20
1003 Payal 21
1004 Amrita 20
1005 Pavan 19
1006 Anchal 19
1007 Ramya 20
1008 Rakesh 21
8 rows selected.
35. Write sql query to display the students in the ascending order of their names for each
course
SQL> SELECT SID, SNAME, DOB, STATE,GENDER, COURSE, CATEGORY FROM STUDENT
GROUP BY SID, SNAME, DOB, STATE, GENDER, COURSE, CATEGORY ORDER BY SNAME;
9 rows selected.
36. Write sql query to delete all the students records who have enrolled for Comp course and
who are born after 2002.
SQL> DELETE FROM STUDENT WHERE COURSE='Comp' AND EXTRACT (YEAR FROM
DOB)>2002
2 rows deleted.
37. Write a sql query to add two new columns Contactno and Email to the existing fields.
Table altered.
Table altered.
38. Write an sql query to display all the Student names where the length of the name is 5
characters.
SNAME
--------------------
Payal
Ramya
E. Create a Table for Library Information : (for questions from 41 to 50) Table name: Library
Constraints: BookId is primary key and BookName is NOT NULL
Table created.
6 rows selected.
IV. QUERIES ON LIBRARY TABLE
39. . Write sql query to display the list of authors from Himalaya publications.
AUTHOR
--------------------
OP Aggarwal
SC Gupta
40. Write sql query to display the total cost of books purchased Publisher wise
PUBLISHER TOTAL_PRICE
-------------------- -----------
Kalyani 1250
Himalaya 1350
TMH 900
PHI 750
41. Write sql query to count the total number of books under Kalyani publications.
KALYANI_PUB_BOOKS
-----------------
Table altered.
43. Write a sql query to display the books in the ascending order of DatePurchased.
6 rows selected.
44. Write sql query to create an index on the fields BookName and Author.
Index created.
45. Write sql query to display the books whose price is between 500 and 700
SQL> SELECT * FROM LIBRARY WHERE PRICE BETWEEN 500 AND 700;
46. Write sql query to increase the price of all the books by 200 for publishers other than
Himalaya or Kalyani
SQL> UPDATE LIBRARY SET PRICE = PRICE + 200 WHERE PUBLICATION NOT IN
('Kalyani','Himalaya');
2 rows updated.
6 rows selected.
47. Write sql query to display the book details where author name contains the name Sharma
48. Create a view to display the fields BookId and BookName where the Publisher isHimalaya.
SQL> CREATE VIEW LIB_BOOK AS SELECT BOOKID, BOOKNAME FROM LIBRARY WHERE
PUBLICATION='Himalaya';
View created.
BOOKID BOOKNAME
---- --------------------------------------------------