Dbms File
Dbms File
Ex.2
CAR (Registration-No, Chassis-No, Engine-No, Company-Name, Model, Year-
Model, Price)
PERSON ( Aadhar-No, Name, Address, City)
OWN-BY (Registration-No, Aadhar-No)
DRIVER (License-No., Date-of-Issue, Valid-up-to, Aadhar-No.)
Code :
use experiment1;
(chasis_no varchar(45),
engine_no varchar(45),
reg_no varchar(45),
comapny varchar(20),
model char(20),
year_manu int,
price float);
describe car;
(adhaar float,
name_p varchar(30),
address varchar(50),
city varchar(40));
describe person;
adhaar float);
describe own_by;
(license_no float,
date_of_issue float,
valid_upto float,
adhaar float);
describe driver;
use experiment1;
values('sdfguibl','a7852413',’a70245’,’hundai’,’creta’,2017,700000);
values('1234567890',’Aady’,’21-D’,’faridabad’);
values(12345678,12081995,01042025,123456789012);
values(’a70245’,'1234567890');
Output-
Car database
Person:
Own by:
Driver:
STUDENT (Roll-No., Name, Father-Name, Mother-Name, City, Dept-Code)
DEPARTMENT (Dept-Code, Dept-Name, Dept-Head)
PROGRAM (Degree-Name, Discipline-Name)
ENROLLED (Roll-No., Degree-Name)
use experiment1_2;
(roll int ,
name_s varchar(45),
father_name varchar(45),
mother_name varchar(45),
city varchar(50),
dep_code char(20));
(dep_code char(20),
dep_name varchar(30),
dep_head varchar(20));
(roll int,
deg_name varchar(20));
(deg_name varchar(20),
dis_name varchar(20));
describe student;
describe department;
describe enrolled;
describe program;
values(12112120,'Aadarsh',’Mukesh’,'Meena',’fbd’,'cspc');
values(12112120,'computer department');
values('btech','computer engineering');
department:
Enrolled:
Program:
Student:
use experiment1_3;
(c_reg_no varchar(45),
c_name char(20),
address varchar(30));
(c_reg_no varchar(45),
adhaar float);
(adhaar float,
name varchar(30),
father_name varchar(30),
dob float,
address varchar(40));
values(‘424vc’,’Aady’s,'fbd');
values((‘424vc’,1234567890);
values(1234567890,'Aadarsh','Mukesh',230820003,'fbd');
Output:
Company:
Owned by:
Person:
Code:
use experiment1_4;
(access_no int,
author varchar(20),
title varchar(20),
subject_code char(10));
(mem_no int,
type_mem varchar(20));
(roll int,
dept_name varchar(20),
program varchar(10));
(empl_code int,
name_e varchar(25),
designation varchar(15),
dept_name varchar(20));
(reg_entry_no int,
access_no int,
mem_no int,
date_issue int);
(access_no int,
date_return int,
comment_return varchar(50));
values(1234,'rohan','my life','cspc');
values(789,'student'),
(456,'employee');
values(12112127,'computer','btech');
values(123,'rohan','director','computer');
values(21,1234,789,30082022);
book:
Book issue:
Book return:
Employee:
Member:
Student:
Exp3:
Create a database for the following relational schema and insert tuples.
STUDENT (Roll-No, Name, Gender, Degree, Semester, Contact no, email-id, Guide-No, Group-Code,
Project-No)
STUDENT (Roll-No, Name, Gender, Degree, Semester, Contact no, email-id, Guide-No, Group-Code,
Project-No)
Code:
use Experiment3;
sem int,
contact double,
group_code char(10),
guide_no int,
project_no int,
);
describe students;
describe guide;
values(12112127,"rohan kumar",'M',"Btech",3,8708322262,"[email protected]");
group_code char(10),
);
guide_research_area varchar(40),
);
no_of_students int
);
values("cspc1",3);
values(23,"creating databases","dbms",1,"cspc1","202209");
values(12112127,"rohan kumar",'M',"Btech",3,8708322262,"[email protected]","cspc1",1,23);
values(11,"Ram mohan","dbms","[email protected]");
values("cspc2",3);
values(25,"creating tables","dbms",1,"cspc2","202209");
values(26,"creating tables","dbms",11,"cspc2","202209");
values(110012,"ramesh kumar",'M',"Btech",3,8708234862,"[email protected]","cspc2",1,25);
update students
set guide_no = 11
values(15,"mukesh","coa","[email protected]");
values(10,"Rohit","dsa","[email protected]");
insert into students
values(110013,"rohit",'M',"Btech",3,8708234862,"[email protected]","cspc2",15,27);
values(110014,"aman",'M',"Btech",3,8744542348,"[email protected]","cspc2",15,27);
values(110015,"tripathi",'M',"Btech",3,8708934662,"[email protected]","cspc2",15,27);
values(27,"address mode","coa",15,"cspc2","202209");
values("cspc3",3);
values("cspc4",3);
values("cspc5",3);
values("cspc6",3);
insert into groupss
values("cspc7",3);
values(16,"pooja","ai","[email protected]"),
(17,"divya","networking","[email protected]"),
(18,"ankit","coa","[email protected]"),
(19,"rohan","programming","[email protected]"),
(20,"mayank","programming","[email protected]"),
(21,"jatin","networking","[email protected]");
values(7,"gr23","ai",16,"cspc3",202208),
(8,"g65","ai",16,"cspc1",202208),
(5,"g76","networking",17,"cspc4",201906),
(12,"vaayuu","coa",18,"cspc3",201906),
(21,"teja","programming",19,"cspc5",201903),
(29,"rafale","networking",17,"cspc1",202203),
(30,"pqr","networking",17,"cspc7",201812),
(31,"abc","ai",16,"cspc6",202205);
values(12112100,"manish",'M',"btech",3,8646846846,"[email protected]","cspc3",18,12),
(12112101,"abhishek",'M',"btech",3,5415416535,"[email protected]","cspc4",17,30),
(12112102,"manish",'M',"btech",3,8646846846,"[email protected]","cspc3",18,12),
(12112103,"yuvraj",'M',"btech",3,5415416535,"[email protected]","cspc4",17,30),
(12112104,"aayush",'M',"btech",3,54965416535,"[email protected]","cspc5",19,21),
(12112105,"aayush2",'M',"btech",3,54965416535,"[email protected]","cspc5",19,21),
(12112106,"monu",'M',"btech",3,54965416535,"[email protected]","cspc7",17,29),
(12112107,"monu2",'M',"btech",3,54965416535,"[email protected]","cspc7",17,29);
values(110017,"Stripathi",'M',"Btech",3,8708934662,"[email protected]","cspc6",17,5);
values(110018,"Sachin",'M',"Btech",3,8708934662,"[email protected]","cspc6",16,8);
values(110020,"Suresh",'M',"Btech",3,8704634662,"[email protected]","cspc1",16,8);
Queries :
1.Update details of the guide of the student whose Roll-no is ‘110011’. The details of the new guide
are as Guide-name =‘Ram Mohan’ & Guide-No = ‘11’.
update students
2.Remove Guide details where Guide-No is ‘15’ and assign a new guide with Guide-No '10' to all the
students who were earlier assigned to the guide with Guide-No '15'.
update project as p
set p.guide_no = 10
update students
set guide_no=10
where guide_no=15;
3.Get a list of guides who are guiding more than two groups of students.
select *
from guide
Output:
4.Get a list of Project-No, Project-title, and names of guides who are guiding projects in the Project
area 'Database'.
select project_no,project_title,guide_name
Output:
select project_title
from project
where project_no = 5;
Output:
(6). Get names of all the students of the project no. ‘5’.
select s_name
from students
where project_no = 5;
Output:
select project_no,project_title,project_year_month
(8). Get names of all the students being guided by ‘Dr. S K Jain’.
select s_name
from students
select *
from project
select *
from project
(11). Lists roll numbers and names of all the students who have their projects in Project area
“Programming”.
select s_name,roll_number
(12). List names of all the teachers who are guiding projects to the students in the Project area
“Network”.
(13). List names of all the students who have their projects in the Project area “Artificial
Intelligence”.
select s_name
15). Whether Project-No ‘7’ was guided by ‘Dr. S K Jain’ in ‘Dec 2020’.
select *
from project
from guide
where guide_name = "SK jain");
select *
select guide_name
from guide
from students
select group_code
from students
where guide_no in( select guide_no from guide where guide_name = "SK jain");
Exp4:
Using SQL statements, compute the following join operations on the above tables Employee and
Department:
1. Cartesian product
2. Natural join
3. Left outer join
4. Right outer join
5. Full outer join
6. Left semi-join
7. Right semi-join
Code:
use experiment4;
name_e varchar(45),
dept_name varchar(45) ,
describe Employee;
manager varchar(30));
values("sales","ram"),
("finance","reeta"),
("accounts","rohit"),
("office","mohit"),
("inventory","rohan");
insert into Employee
values(1101,"ramesh","sales"),
(2241,"suresh","finance"),
(2242,"kamal","sales"),
(2243,"ankur","inventory"),
(2245,"vikas","office"),
(2246,"sumit","sales");
update Employee
values("health","tripathi"),
("technology","shashank"),
("financial advisor","akshat");
select *
on employee.dept_name = department.dept_name;
-- 4. right outer join
select *
on employee.dept_name = department.dept_name;
on employee.dept_name = department.dept_name)union
select dept_name,employee_id,name_e
SECTION (Course-id, sec-id, semester, year, building, room-number, Time-slot-id, day, start-time)
Code:
use university_database;
(time_id int ,
day varchar(12) ,
);
(course_id varchar(10),
sec_id varchar(10),
sem int,
year int ,
building varchar(45),
room_no varchar(10),
time_slot_id int,
day varchar(12),
start_time varchar(5),
primary key(course_id,sec_id,sem,year)
);
building varchar(25),
budget int );
(i_id int ,
course_id varchar(10),
sec_id varchar(10),
sem int ,
year int,
primary key (i_id,course_id,sec_id,sem,year));
(s_id int ,
course_id varchar(10),
sec_id varchar(10),
sem int ,
year int ,
grade char,
);
title varchar(15),
credits int,
name varchar(12),
dept_name varchar(20),
salary int,
name varchar(20),
dept_name varchar(20),
tot_cred int ,
i_id int ,
(course_id varchar(10),
prereq_id varchar(10),
primary key(course_id,prereq_id),
(building varchar(45),
room_no varchar(10),
capacity int ,
("Electrical department","E-101",85),
("Electrical department","E-102",85),
("Electrical department","E-201",85),
("Electrical department","E-202",85),
("Electrical department","E-301",85),
("L-Block","L-1",85),
("L-Block","L-2",85),
("L-Block","L-3",85),
("L-Block","L-4",85),
("L-Block","L-5",85);
values("Computer","Computer",25000),
("IT","Computer",20000),
("ECE","L-Block",25000),
("Electrical","Electrical",20000),
("Civil","AB-Block",25000),
("Mechnical","Applied Mechanics",20000),
("PIE","AB-Block",20000);
values("cspc-11","daa","computer",3),
("cspc-12","java","computer",3),
("cspc-13","web-d","computer",3),
("cspc-14","c++","computer",3),
("cspc-15","c","computer",3),
("cspc-16","dsa","computer",3),
("itpc-12","java","computer",3),
("itpc-13","web-d","computer",3),
("itpc-14","c++","computer",3),
("itpc-15","c","computer",3),
("itpc-16","dsa","computer",3);
values("itpc-20","dbms","IT",3),
("itpc-25","os","IT",3);
values("cspc-46","computerNetwork","computer",4);
values("cspc-47","cLanguages","computer",4);
values(11,"JK CHABRA","Computer",150000),
(12,"Mayank dave","Computer",140000),
(13,"AK singh","Computer",160000),
(21,"Vijay verma","Computer",100000),
(22,"Mukesh kumar","ECE",100000),
(41,"PrashadJoshi","Mechnical",150000),
(56,"GauravMathur","Civil",140000);
values(95,"Mohan majee","IT",90000);
values(100,"rohan","computer",125,11),
(101,"Stripathi","computer",102,12),
(103,"Akshat","Mechnical",65,41),
(105,"Shashank","computer",95,11),
(157,"Sanyam","ECE",110,22),
(574,"pDubey","computer",99,11),
(952,"Samraat","computer",100,21),
(735,"chanks","IT",112,13);
values(562,"rajKumari","IT",75,22);
values(1,"Monday","08:30","09:25"),
(2,"Monday","09:30","10:25"),
(3,"Monday","10:30","11:25"),
(4,"Monday","11:30","12:25"),
(5,"Monday","12:30","13:25"),
(1,"Tuesday","08:30","09:25"),
(3,"Tuesday","12:30","13:25"),
(5,"Tuesday","08:30","09:25"),
(1,"Friday","08:30","09:25"),
(2,"Friday","09:30","10:25"),
(4,"Friday","11:30","12:25"),
(1,"Saturday","08:30","09:25"),
(2,"Saturday","09:30","10:25"),
(4,"Saturday","11:30","12:25");
("itpc-11","it-a",3,2,"L-Block","L-1",1,"Monday","08:30"),
("itpc-13","it-a",3,2,"Electrical department","E-101",3,"Saturday","10:30"),
("itpc-11","it-b",3,2,"L-Block","L-5",2,"Tuesday","09:30"),
("itpc-12","it-b",3,2,"Electrical department","E-201",5,"Friday","13:30");
-- data for teaches
values(11,"cspc-14","cs-b",3,2),
(11,"cspc-11","cs-a",3,2),
(12,"cspc-12","cs-a",3,2),
(13,"cspc-13","cs-b",3,2),
(12,"cspc-12","cs-c",3,2),
(21,"itpc-11","it-b",3,2),
(13,"itpc-13","it-a",3,2),
(11,"itpc-12","it-b",3,2);
values(22,"cspc-47","cs-b",3,2);
values
(100,"cspc-13","cs-b",3,2,"A"),
(100,"cspc-14","cs-b",3,2,"A"),
(100,"cspc-15","cs-b",3,2,"A"),
(101,"cspc-16","cs-a",3,2,"B"),
(101,"cspc-11","cs-a",3,2,"A"),
(105,"cspc-12","cs-c",3,2,"B"),
(105,"cspc-13","cs-c",3,2,"C"),
(105,"cspc-16","cs-c",3,2,"B"),
(735,"itpc-11","it-a",3,2,"B"),
(735,"itpc-13","it-a",3,2,"B");
values
("cspc-11","cspc-15"),
("cspc-16","cspc-15"),
("itpc-16","itpc-15"),
("cspc-12","cspc-14");
Exp5:
-- 1.Increase Salary by 20 percent of all instructors who are working in Department IT.
update instructor
select salary
from instructor
select name,dept_name
from instructor;
-- 3.Retrieve names of all instructors along with their department names and building names in
which the departments are housed.
select i.name,i.dept_name,d.building
-- 4.Retrieve names of all departments along with names of the buildings in which they are situated.
select dept_name,building
from deaprtment;
-- 5. Change name of the building "Lecture Hall Complex" to "Lecture Theatre Complex".
update classroom
-- 6. Find name of the department of a student with ID _____. (Take a valid ID value of a student)
select name
from student
-- 7. Retrieve names of all instructors along with the Course IDs of the courses they teach.
select i.name,c.course_id
select t.course_id,t.sem,t.year,c.title
-- 9. Compute monthly salary of all instructors and display it as 'monthly salary' attribute in place of
attribute 'salary'.
from instructor;
-- 10. Retrieve names of all departments housed in the building named _______. (Consider a valid
Building name)
select dept_name
from deaprtment
-- 11. Find the names of all instructors belonging to Computer Engg. department who have salary
greater than Rs. 70,000.
select name,salary
from instructor
-- 12. Find titles of the courses that have credits 3 and offered by the department IT.
select title
from course
select c.title,c.credits
where t.sem = 3;
-- 14. List classes as year and semester wise engaged in room no. LHC-102.
select year,sem,course_id
from section
-- 15. List classes as year, semester and section wise engaged in room no. LHC-102
select year,sem,course_id,sec_id
-- 17. Retrieve list of room number & time slot where all classes of Computer Engg.. Semester 3rd
are scheduled.
select s.room_no,s.time_slot_id from section as s natural join (student natural join takes)
-- 18. Retrieve Course titles taught by instructor _______. (Take a valid instructor ID or name)
select title
from course
where course_id =ANY (select course_id from instructor natural join teaches where i_id = 11);
-- 19. For all instructors in the university who have taught some course, display their names along
with their department names.
-- 20. Find the names of all instructors who have a higher salary than some instructor in "Computer
Engg." department.
select name
from instructor
where salary > (select salary from instructor where i_id = 95);
Exp6:
Write the following queries in the SQL for the above-mentioned database of a university.
(1). Find names of all departments whose building name includes the substring “Hall”.
(2). Find names of all instructors who have their salaries between Rs.
(4). Find names of all students belonging to Computer Engg. department and
their names
(5). Retrieve list of courses taught by teachers whose names begin with
character "S".
(6). Retrieve list of courses beginning their titles with word "o".
(7). Retrieve list of courses containing the word "fa" in their titles.
(8). Retrieve names of the instructors who teach courses containing word
is IT.
(11). Find average salary of the instructors belonging to Computer Engg, department.
(13). Find names and average salaries of all departments whose average
(15). Find total number of courses offered by the Computer Engg department.
(16). Find total number of courses taught in the 3rd semester 2018.
(17). Find total number of instructors who teach a course in the 3rd semester 2018.
(22). Find total number of students enrolled in each department of the university.
(24). Find instructors whose average salaries are greater than that of the instructors belonging to the
'computer engg' department.
(25). Retrieve total no. of students in each department who earned total credits more than 9.7.