Docsity

SQL Lab reports SQL Lab reports, Lab Reports of Computer Science

Toggle sidebar
bg1
Assignment 1
Create a course table by using course id, course name, fee and HOD name of that course.
Q1. Creation of table.
create table course_table(
Course_Id number(10),
CName varchar(10),
Fee number(5),
Hud varchar(15));
desc course_table;
insert into course_table values(101,'BBA',80000,'Dr.Manoj');
insert into course_table values(102,'BCA',82000,'Dr.Sarita');
insert into course_table values(103,'B.Com(H)',74000,'Dr.Manju');
insert into course_table values(104,'BA.Eco(H)',77000,'Dr.Vinita');
select * from course_table;
Q2. Delete course Id 101.
Delete from course_table where Course_ID=101;
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Partial preview of the text

Download SQL Lab reports SQL Lab reports and more Lab Reports Computer Science in PDF only on Docsity!

Assignment 1

Create a course table by using course id, course name, fee and HOD name of that course. Q1. Creation of table. create table course_table( Course_Id number(10), CName varchar(10), Fee number(5), Hud varchar(15)); desc course_table; insert into course_table values(101,'BBA',80000,'Dr.Manoj'); insert into course_table values(102,'BCA',82000,'Dr.Sarita'); insert into course_table values(103,'B.Com(H)',74000,'Dr.Manju'); insert into course_table values(104,'BA.Eco(H)',77000,'Dr.Vinita'); select * from course_table; Q2. Delete course Id 101. Delete from course_table where Course_ID=101;

Create a course table and student table with 4 and 20 entries respectively.

Creation of course table. create table course_table( Course_Id number(10), CName varchar(10), Fee number(5), Hud varchar(15)); desc course_table; Inserting entries. insert into course_table values(101,'BBA',80000,'Dr.Manoj'); insert into course_table values(102,'BCA',82000,'Dr.Sarita'); insert into course_table values(103,'B.Com(H)',74000,'Dr.Manju'); insert into course_table values(104,'BA.Eco(H)',77000,'Dr.Vinita'); select * from Student_ID02; Delete Course Id 101 Delete from course_table where Course_ID=101; Creation of student table. create table Student_ID02( Enrollment_ no number(05), Name varchar(15), House_no number(20), colony varchar(10), state varchar(10), country varchar(10), pincode number(06), Mobile number(10),

Inserting entries in student table insert into Student_ID01 values(01147,'ankit',23,'rohini','Delhi','India',110045,8510928878,101,' nov 1999') insert into Student_ID values(02147,'Samyak',23,'janakpuri','Delhi','India',110045,8510928878,102,'12 nov 1999') insert into Student_ID01 values(03147,'Sidhart',23,'dwarka','kolkata','uk',110045,8510928878,101,' nov 1999') insert into Student_ID values(04147,'Apoorv',23,'dwarka','kolkata','uk',110045,8510928878,102,'12 nov 1997') insert into Student_ID values(05147,'Prateek',23,'paschim','mumbai','us',110046,8510928878,104,'16 dec 1999') insert into Student_ID values(06147,'Piyush',23,'paschim','mumbai','us',110046,8510928878,103,'13 dec 1999') insert into Student_ID values(07147,'Kunal',26,'paschim','mumbai','us',110046,8510928878,103,'16 dec 1998') insert into Student_ID values(08147,'Ananya',23,'paschim','mumbai','us',110046,8510928878,104,'17 dec 1997') insert into Student_ID values(09147,'Muskan',23,'paschim','mumbai','us',110046,8510928878,102,'13 dec 1999') insert into Student_ID values(10147,'Varsha',23,'paschim','mumbai','us',110046,8510928878,101,'13 dec 1999') insert into Student_ID values(11147,'Vrinda',23,'janakpuri','delhi','japan',110046,8510928878,103,'13 dec 1999')

Answer the following on the bases of course and student table. Q1. Add one column of email id in student table. alter table student_id02 add email_id varchar(20); Q 2. Change the size of name to 40 in student table. alter table student_id02 modify name varchar(40); Q 3. Add new field landline number in student table. alter table student_id02 add landline_number number(10);

Q6. Delete student data whose roll number is less then 05147 Delete from student_ID01 where enroll_no <01547; Q7. Display student who live in US select * from student_ID where Country='US' Q8. Display all students who lived in colony Janakpuri and country UK. select * from student_ID where colony='Janakpuri' and country='UK'; Q9. Display all students who lived in Janakpuri or Rohini. select * from student_ID where colony='Janakpuri' or colony='Rohini';

Q10.

Display all students whose name starts with S. select name from student_ID01 where name like 'S%'; Q11. Display all students whose name starts with P or A. select name from student_ID where name like 'P%' or name like 'A%'; Q12. Display all students whose starts with P and end with H. select name from student_ID where name like 'P%h' Q13. Display all students whose second letter is A and last letter is H. select name from student_ID where name like '_a%h'

Q17. Display the name of HOD of BJMC

select HOD from course where course_name='BJMC'

Q18. Display all students who are born after 1st^ Jan 1998

select * from student_ID where DOB > '01 jan 1998'

Q19. Display all students who are born between 1st^ Jan 1998 and 31st^ Dec 1998

select * from student_ID where DOB between '01 jan 1998' and '31 dec 1998'

Q20. Display all course whose fees between 70000 and 90000.

select * from course where fees between '70000' and '90000'

Q24. Display student enrolment no., name and fees of BJMC students.

select enroll_no,name from student_ID where courseid =(select courseid from course where course_name='BJMC');

Q25. Display all students whose fees is greater than 80000

select * from student_ID where courseid in(select courseid from course where fees>80000);

Q26. Display all students whose fees is less than 90000

select * from student_ID where courseid in(select courseid from course where fees<90000);

Assignment 3

Create a Department and an employ table with 4 department heads and 20 employees respectively in them. Creation of Department table where Deptld is a primary key. create table Dept_table( DEPTLD NUMBER(03) PRIMARY KEY, DNAME VARCHAR(10) CHECK(DNAME IN('HR','IT','FINANCE','MARKETING')), DLOCATION VARCHAR(10), DEPT_HEAD VARCHAR(10));

Creating employee table where DEPLD is a foreign key. create table Employee_table( EID NUMBER(03) PRIMARY KEY, ENAME VARCHAR(10), DOB DATE CHECK(DOB >='1 JAN 1990'), PHONE NUMBER(10), DOJ DATE, PROJECT VARCHAR(5) CHECK(PROJECT IN('P1','P2','P3','P4')), SALARY NUMBER(6) CHECK(SALARY >10000 AND SALARY <100000),

DEPTLD NUMBER(03),

FOREIGN KEY (DEPTLD) REFERENCES Dept_table(DEPTLD)); Inserting employee’s data INSERT INTO EMPLOYEE_TABLE VALUES(101,'PRAVEEN SHARMA',9810014490,'20 JAN 1992','25 SEP 2009',222,'P3',50000); INSERT INTO EMPLOYEE_TABLE VALUES(102,'AMIT POPLI',9810014491,'18 DEC 1993',' OCT 2011',444,'P2',51000); INSERT INTO EMPLOYEE_TABLE VALUES(103,'PRAVEEN JINDAL',9810014492,'10 FEB 1992','24 NOV 2006',111,'P1',52000); INSERT INTO EMPLOYEE_TABLE VALUES(104,'ASHISH KALRA',9810014493,'13 NOV 1993','14 JUN 2013',333,'P2',53000); INSERT INTO EMPLOYEE_TABLE VALUES(105,'NEERAJ ARORA',9810014494,'10 JAN 1992','28 APR 2005',222,'P3',54000); INSERT INTO EMPLOYEE_TABLE VALUES(106,'M K GUPTA',9810014495,'08 MAR 1994',' MAY 2001',111,'P4',55000); INSERT INTO EMPLOYEE_TABLE VALUES(107,'R RAJKUMAR',9810014496,'06 OCT 1993',' JAN 2013',444,'P3',56000); INSERT INTO EMPLOYEE_TABLE VALUES(108,'DARSHAN KHARE',9810014497,'04 APR 1995','28 FEB 2012',333,'P2',57000); INSERT INTO EMPLOYEE_TABLE VALUES(109,'BAWAN BORANA',9810014498,'02 SEP 1993','05 AUG 2011',222,'P1',58000); INSERT INTO EMPLOYEE_TABLE VALUES(110,'RAHUL GARG',9810014499,'29 MAY 1992',' JUL 2010',111,'P2',59000); INSERT INTO EMPLOYEE_TABLE VALUES(111,'SIKHA GARG',9810014495,'27 JUL 1992',' OCT 2017',222,'P3',60000);

Assignment 4

Answer the following on the bases of department and employ table. Q1. Display all employees who are working in HR department select d.DEPTLD,d.DNAME,d.DEPT_HEAD,d.dlocation,e.EID,E.ENAME from Dept_table d, Employee_table e WHERE E.DEPTLD = d.DEPTLD; Q2. Display all employees whose salary is <50,000 and working in the IT department. SELECT * FROM Employee_table where salary <50000 and DEPTLD=(Select DEPTLD from Dept_table where DNAME='IT');

Q3. Display all employees who joined before 2010. SELECT * FROM Employee_table where doj> '01 jan 2010'; Q5. Display the Average salary of the HR Department. SELECT avg(salary) FROM Employee_table where DEPTLD= 111; Q6. Display Max salary of finance department. SELECT max(salary) FROM Employee_table where DEPTLD=(Select DEPTLD from Dept_table where DNAME='FINANCE'); Q7. Display Min salary of IT department