Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
42 views10 pages

RDBMS LAB Record ALL Tables

The document contains SQL commands for creating and manipulating various database tables, including Supplier, Employee, Department, Student, and Library. It includes commands for inserting records, querying data, updating records, and creating views and indexes. The queries cover a wide range of operations such as filtering, sorting, and aggregating data based on specific conditions.

Uploaded by

Coder kids
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)
42 views10 pages

RDBMS LAB Record ALL Tables

The document contains SQL commands for creating and manipulating various database tables, including Supplier, Employee, Department, Student, and Library. It includes commands for inserting records, querying data, updating records, and creating views and indexes. The queries cover a wide range of operations such as filtering, sorting, and aggregating data based on specific conditions.

Uploaded by

Coder kids
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/ 10

SQL>Create table Supplier22(sup_no varchar(2) primary key,sup_name varchar(8),item_supplied

varchar(10),item_price number(4),city varchar(10));

Insert Records

SQL> insert into supplier22 values('S1','SURESH','KEYBOARD',400,'HYDERABAD');

SQL> insert into supplier22 values('S2','KIRAN','PROCESSOR',8000,'DELHI');

SQL> insert into supplier22 values('S3','MOHAN','MOUSE',350,'DELHI');

SQL> insert into supplier22 values('S4','RAMESH','PROCESSOR',9000,'BANGALORE');

SQL> insert into supplier22 values('S5','MANISH','PRINTER',6000,'MUMBAI');

SQL> insert into supplier22 values('S6','SRIKANTH','PROCESSOR',8500,'CHENNAI');

Queries

Q1) Write sql query to display supplier numbers and supplier names whose name starts with ‘R’.

SQL> select sup_no,sup_name from supplier22 where sup_name like 'R%';

Q2) Write sql query to display the name of suppliers who supply Processors and whose city is Delhi.

SQL> select sup_name from supplier22 where item_supplied='Processor' and city='Delhi';

Q3) Write sql query to display the names of suppliers who supply the same items as supplied by Ramesh.
SQL> select sup_name from supplier22 where item_supplied=(select item_supplied from supplier22
where sup_name='Ramesh');

Q4)Writesql query to increase the price of keyboard by 200.

SQL> update supplier22 set item_price=item_price+200 where item_supplied='Keyboard';

Q5) Write sql query to display supplier numbers, supplier names and item price for suppliers in delhi in
the ascending order of item price.

SQL> select sup_no,sup_name,item_price from supplier22 where city='Delhi' order by item_price;

Q6) Write sql query to add a new column called contact no.

SQL> alter table supplier22 add(contact_no number(10));

Q7) Writesql query to delete the record whose itemprice is lowest of all the items supplied.

SQL> delete from supplier22 where item_price<=(select min(item_price) from supplier22);

Q8)Create a view on the table which displays only supplier numbers and supplier names.

SQL> create view supplier_v as select sup_no,sup_name from supplier22;

Q9) Write sql query to display the records in the descending order of itemprice for each itemsupplied.

SQL> select *from supplier22 order by item_price desc;

Q10) Write sql query to display the records of suppliers who supply items other than processors or
keyboard.

SQL> select *from supplier22 where item_supplied not in('Processor','Keyboard');


SQL>create table empdetails(eid varchar(4) primary key, ename varchar(8), dob date, desg varchar(10),
sal number(5),doj date);

Insert Records

SQL>insert into empdetails values('e101','suma','29-dec-89','designer',20000,'1-apr-10');

SQL>insert into empdetails values('e102','amit','10-jan-95','programmer',25000,'18-feb-18');

SQL>insert into empdetails values('e103','payal','15-aug-83','tester',35000,'13-jun-11');

SQL>insert into empdetails values('e104','kiran','20-apr-90','programmer',40000,'7-mar-14');

SQL>insert into empdetails values('e105','meenal','29-may-83','dba',50000,'9-dec-11');

SQL>insert into empdetails values('e106','sheela','1-may-70','analyst',60000,'25-sep-18');

SQL>insert into empdetails values('e107','swamy','13-jan-85','programmer',45000,'14-feb-16');

SQL>insert into empdetails values('e108','sushma','22-dec-76','dba',45000,'31-jan-1');

Queries

Q11)Write sql query to display all the employees whose designation is programmer.

SQL> select *from emp where desg='programmer';


Q12)Write sql query to display employees who have joined after 2014.

SQL> select *from emp where extract(year from doj)>2014;

Q13)Write sql query to display all the employees whose name ends with ‘a’.

SQL> select *from emp where enamelike'%a';

Q14)Write sql query to display the total salary of all the employees whose designation is programmer.

SQL> select sum(sal) from emp where desg='programmer';

Q15)Write sql query to display all the employee names in upper case.

SQL> select upper(ename) from emp;

Q16)Write sql query to display the details of the employee with highest experience.

SQL> alter table emp add(experience number(3));

SQL> update emp set experience=extract(year from sysdate)-extract(year from doj);

SQL> select *from emp where experience>=(select max(experience) from emp);

Q17)Write sql query to display the details of the employees whose name contains ‘ee’.

SQL> select *from emp where ename like '%ee%';

Q18)Write sql query to increase the salaries of employees by 5000 whose designation is dba.

SQL> update emp set sal=sal+5000 where desg='dba';

Q19)Write sql query to display the employees whose salary is more than the average salary of all the
employees.

SQL> select *from emp where sal>(select avg(sal) from emp);

Q20)Write sql query to display the record in the following format:

xxxxxxx is working as xxxxxxxxx with a salary ofRs.xxxxxxxxxx.

eg: Suma is working as Designer with a Salary ofRs.20000

SQL>select ename || 'is working as' || desg || 'with a salary of Rs:'|| sal from emp;
Create Department Table and Insert Record

Sql>create table department2024(deptid varchar(2) primary key, dname varchar(20));

Sql>insert into department2024 values('d1','sales');

Sql>insert into department2024 values('d2','Marketing');

Sql>insert into department2024 values('d3','finance');

Sql>commit;

Sql>select *from department2024;

Create Employee Table and Insert Record

Sql>create table emp2024(eid number(3) primary key, ename varchar(20), deptid varchar(2), designation
varchar(20),salary number(6),doj date,constraint fk_emp2024 foreign key(deptid) references
department2024(deptid));
Sql>insert into emp2024 values(101,'sudha','d2','clerk',20000,'1-apr-10');

Sql>insert into emp2024 values(102,'david','d1','manager',50000,'18-feb-18');

Sql>insert into emp2024 values(103,'preethi','d3','clerk',35000,'13-jun-11');

Sql>insert into emp2024 values(104,'kiran','d1','salesman',20000,'07-mar-14');

Sql>insert into emp2024 values(105,'meenal','d2','clerk',50000,'09-dec-11');

Sql>insert into emp2024 values(106,'sunitha','d3','manager',60000,'25-sep-18');

Sql>insert into emp2024 values(107,'akhil','d3','clerk',25000,'14-feb-16');

Sql>insert into emp2024 values(108,'sushma','d2','manager',45000,'31-jan-12');

Queries

21)Write sql query to display all the employees who are more than average salary of all the employees in
the company.

SQL> select *from employee where sal>=(select avg(sal) from employee);

Q22)Write sql query to display the fields eid, ename and dname.

SQL> select eid,ename,dname from employee e,dept d where e.deptid=d.deptid;

Q23)Write sql query to sort the employee table in the descending order of salaries.

SQL> select *from employee order by saldesc;

Q24)Write sql query to list all the job designations in the employee table without repetitions.

SQL> select desg from employee group by desg;

Q25) Write sql query to display all the employee details department wise and in the ascending order.

SQL> select *from employee e,dept d where e.deptid=d.deptid order by dname;

Q26)Write sql query to display all the clerks in deptid d2.

SQL> select *from employee where deptid='d2' and desg='clerk';

Q27)Write sql query to display all the employees who joined in the year 2011.

SQL> select *from employee where doj between '01-jan-2011' and '31-dec-2011';

Q28)Write sql query to display all the employees who joined in the month of February.

SQL> select *from employee e where extract(month from e.doj)=2;

Q29)Write sql query to display all the employees whose salary is between30000 and 45000.
SQL> select *from employee where sal between 30000 and45000;

Q30) Write sql query to display all the employee details along with their work experience in the

company till current date.

SQL> select eid,ename,deptid,desg,sal,doj,extract(year from sysdate)-extract(year from doj) as


experience from employee;

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 .

Sid Sname DOB State Gender Category Course


(Primary
Key)
1001 Neha 29-Dec-02 Telangana F Gen Comp
1002 Arun 10-jan-02 Telangana M OBC Honors
1003 Payal 15-Aug-01 Maharashtra F Gen Appl
1004 Amrita 20-Apr-02 Karnataka F OBC Honors
1005 Pavan 29-May-03 Andhra Pradesh M Exservicemen Comp
1006 Anchal 1-May-03 Gujarat F OBC Comp
1007 Ramya 13-Jan-02 Telangana F Gen Appl
1008 Rakesh 22-Dec-01 Andhra Pradesh M Sports Comp

SQL>Create table Student(Sid varchar(2) primary key, Sname varchar(8),DOB date ,state varchar2(10),
Gender varchar2(1) , Category varchar2(10));

Insert Records

SQL> insert into Student values(‘1001’,Neha’,’29-Dec-02’,Telangana’,’F’,’Gen’,’Comp’)

SQL> insert into Student values(‘1002’,’Arun’,’10-Jan-02’,Telangana’,’M’,’OBC’,’Honors’);

SQL> insert into Student values(‘1003’,Payal’, ’15-Aug-01’, ’Maharastra’, ’F’, ’Gen’, ’Appl’);

SQL> insert into Student values(‘1004’,Amrita’,’20-Apr-02’,Karnataka’,’F’,’OBC’,’Honors’);

SQL> insert into Student values(‘1005’,Pavan’,’29-may-03’,Andhra


Pradesh’,’M’,’Exservicemen’,’Comp’);

SQL> insert into Student values(‘1006’,Anchal’,’01-May-03’,Gujarat’,’F’,’OBC’,’Comp’);

SQL> insert into Student values(‘1007’,Ramya’,’13-Jan-02’,Telangana’,’F’,’Gen’,’Appl’)

SQL> insert into Student values(‘1008’,Rakesh’,’22-Dec-01’,Andhra Pradesh’,’M’,’Sports’,’Comp’)

SQL> select *from Student;


Q31)Write sql query to display the students who are not from telangana or Andhra Pradesh. SQL> select
*from Student where State not in('Telangana','Andhra Pradesh');

Q32)Create a view to display the columns sid, sname for students belonging to telangana. SQL> SQL>
create view std_telangana as select sid,sname from Student where state in(‘Telangana');

Q33)Write sql query to create an index on column sname.

SQL> create index sindex on Student(sname);

Q34)Write sql query to display all the female students enrolled under comp course and who belong to
obc.

SQL> select *From Student where gender='F' and category='OBC' and course='Comp';

Q35)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;

Q36)Write sql query to display the students in the ascending order of their names from each course.

SQL> SELECT Sid, Sname,Course FROM Student ORDER BY Sname ASC;

Q37)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;

Q38)Write sql query to add two new columns contactno and email to the existing fields.
SQL> alter table Student add(contactno number(10),email varchar2(15));

Q39)Write an sql query to display all the student names prefixed with Mr./Ms. Based on gender column.
SQL> SELECT
CASE
WHEN gender = 'Male' THEN 'Mr. ' || sname
ELSE 'Ms. ' || sname
END
FROM student;

Q40)Write an sql query to display all the student names where the length of the name is 5 characters.
SQL> select sname from std where length(sname)<=5;

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

BookId BookName Author DatePurchased Publisher Price


B101 Cost Accounting Jain Narang 11-Feb-13 Kalyani 800
B102 Business Statistics OP Aggarwal 22-Dec-11 Kalyani 800
B103 RDBMS C J Date 2-Mar-15 Himalaya 750
B104 Mgmt Accounting RK Sharma 19-Apr-16 TMH 900
B105 Operating Systems Galvin 25-Nov-13 Kalyani 450
B106 Advanced Accounting SC Gupta 16-Apr-18 PHI 750

SQL> create table library(bookid varchar2(4) primary key,bookname varchar2(20),author


varchar2(15),datepurchased date,publisher varchar2(10),price number(3));

Insert Records

SQL> insert into library values(‘B101’,’Cost Accounting’,’Jain Narang’,’11-Feb-13’,’Kayani’,800)

SQL> insert into library values(‘B102’,’Business Statistics’,’OP Aggarwal’,’22-Dec-11,’Kayani’,800)

SQL> insert into library values(‘B103’,’RDBMS’,’C J Date’,’2-Mar-15’,’Himalaya’,750)

SQL> insert into library values(‘B104’,’Mgmt Accounting’,’RK Sharma’,19-Apr-16,’TMH’,900)

SQL> insert into library values(‘B105’,’Operating Systems’,’Galvin’,’25-Nov-13’,’Kayani’,450)

SQL>insert into library values(‘B106’,’Advanced Accounting’,’SC Gupta,’16-Apr-18’,’PHI’,750)

Queries

SQL> select *from Student;

Q41)Writesql query to display the list of authors from Himalaya publications.

SQL> select author from library where publisher='himalaya';

Q42)Write sql query to display the total cost of books purchased publisher wise.

SQL> select sum(price),publisher from library group by publisher;

Q43)Write sql query to count the total number of books under kalyani publications.

SQL> select count(*) from library where publisher='kalyani';

Q44)Write sql query to rename the column publisher as publications.

SQL> alter table library rename column publisher to publications;

Q45)Write a sql query to display the books in the ascending order of date purchased.

SQL> select *From library order by purchased;

Q46)Write sql query to create an index on the fields book name and author.
SQL> create index lib_index on library(bookname,author);
Q47)Write sql query to display the books whose price is between 500 and 700.
SQL> select *From library where price between 500 and 700;

Q48)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 publications not in ('himalaya', 'kalyani');

Q49)Writesql query to display the book details where author name contains the name sharma. SQL>
select *From library where author like '%sharma%';

Q50)Create a view to display the fields bookid and bookname where the publisher is Himalaya. SQL>
create view library_himalaya as select bookid,bookname from library where publications in ('himalaya');

You might also like