0% found this document useful (0 votes)
12 views

Lab Report DBMS

Lab Report DBMS

Uploaded by

alt.b9-5ov294pr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab Report DBMS

Lab Report DBMS

Uploaded by

alt.b9-5ov294pr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Thames International College

Database Management System

Submitted by: Submitted to:

Vathsal Vaidya Kishor Singh


Table of Contents

LAB 1...............................................................................1

LAB 2...............................................................................2

LAB 3...............................................................................6

LAB 4...............................................................................8

LAB 5.............................................................................14
LAB 1

Table creation, data insertion and data deletion.


CREATE TABLE SCHOOL(
SchoolID int,
SchoolName varchar(50),
Major varchar(20),
Grade real,
Phone bigint
);
Insert into SCHOOL VALUES(1,'Thames','BIM',3.67,9851312212);
Insert into SCHOOL VALUES(2,'SXC','BBA',3.57,9852314412);
Insert into SCHOOL VALUES(3,'Prime','BBM',3.27,9851312232);
Insert into SCHOOL VALUES(4,'SDC','BCA',3.97,9851323412);

Select *from SCHOOL;

Delete from SCHOOL;

1
LAB 2
CREATE TABLE SCHOOL1(
SchoolID int,
SchoolName varchar(50),
Major varchar(10),
Address varchar(50),
Phone int
);

Select *from SCHOOL1;

Insert into SCHOOL1 values(1, 'St. Xaviers', 'Management',


'Jawalakhel', 0123);
Insert into SCHOOL1 values(2, 'Xavier Academy', 'Science', 'Lazimpat',
0309);
Insert into SCHOOL1 values(3, 'Little Angels', 'Maths', 'Hattiban',
0369);
Insert into SCHOOL1 values(4, 'St. Marys', 'Science', 'Jawalakhel',
0420);
Insert into SCHOOL1 values(5, 'GEMS', 'Science', 'Dhapakhel', 6969);

Alter table SCHOOL1 add grade real; --TO ADD NEW COLUMN

2
Insert into SCHOOL1 values(6, 'Thames', 'BIM', 'Battisputali', 1235,
3.6);
Insert into SCHOOL1 values(7, 'St. Xaviers', 'A levels', 'Maitighar',
2000, 3.8);

Alter table SCHOOL1 alter column Phone bigint; --TO CHANGE DATA TYPE

Insert into SCHOOL1 values(8, 'Liverpool', 'Management', 'Baneshwor',


123456789, 2.89);

3
Update SCHOOL1 set grade = 2.3; --TO REPLACE NULL IN GRADE
Update SCHOOL1 set grade = 3.8 where SchoolID = 1;

Delete from SCHOOL1 where Address = 'Jawalakhel';

4
Alter table SCHOOL1 add constraint my_constraint unique(Address); --TO
ADD CONSTRAINT

Truncate table SCHOOL1; --TO REMOVE DATA FROM THE TABLE

sp_rename 'SCHOOL1', 'INSTITUTION'; --TO RENAME THE TABLE NAME

Select *from INSTITUTION;

Drop table INSTITUTION; --TO DROP THE TABLE

5
LAB 3
CREATE TABLE College(
CollegeID int,
CollegeName varchar(50),
Major varchar(10),
Address varchar(50),
Phone int,
Grade int);

Insert into College values(1,'Thames International', 'BIM',


'Battisputali', 1333, 3.2);
Insert into College values(2,'Kings', 'BBA', 'Buddhanagar', 1233,
3.24);
Insert into College values(3,'St. Xaviers', 'Bsc.CSIT', 'Maitighar',
1234, 3.48);
Insert into College(CollegeID, CollegeName, Major, Address, Phone,
Grade) values(4, 'Prime', 'BBM', 'Khusibu', 2313, 3.6);
Insert into College(CollegeID, CollegeName, Major, Address, Phone,
Grade) values(5, 'Shanker Dev', 'BCA', 'Putalisadak', 2334, 2.76);
Insert into College(CollegeID, CollegeName, Major, Address, Phone)
values(6, 'Ace', 'BBS', 'Sinamangal', 2322);
Insert into College(CollegeID, CollegeName, Major, Address, Phone)
values(7, 'KIST', 'BHM', 'Kamal Pokhari', 2332);

Select *from College;

Select distinct major from College;

Select *from College where CollegeID = 1;

Select *from College where CollegeID in (1,2,3,4);

Select CollegeID from College where CollegeName = 'Thames


International';

Select *into NewStudent from College; --To transfer data to new table

6
Select CollegeName from College where Phone > 4;

Select Phone+5 from College; --Adds +5 in Phone

Update College set Phone = 9842;

Update College set Phone = 9851 where CollegeID = 1;

Update College set Phone = Phone * 1.50 where CollegeID = 5;


Delete from College where CollegeID = 5; --To delete a value from
table where CollegeID is 5

Update College set CollegeID = 100 where CollegeName = 'Thames


International';

7
LAB 4
SELECT * FROM [SUPERMICRO\user51].[College] --To fetch previous table

Select top 1 * from College;


Select top 2 * from College;

Select *from College order by Grade asc;

--Find the details of top two students


Select top 2* from College order by Grade desc;

--Select distinct address from college


Select distinct Address from College;

8
--Select name from College where grade between 3 and 5.
Select CollegeName from College where Grade between 3 and 5;

--Select name from college where id = 2 or id = 3 or id = 4


Select CollegeName from College where CollegeID in(2,3,4,10);

--Select name from college where id in (2,3,4,5,6)


Select CollegeName from College where CollegeID in(2,3,4,5,6);

--Find the name of college/student starting with 'a'


Select CollegeName from College where CollegeName like 'a%';

--Find the names starting with 'a' but having 3 characters only

9
Select CollegeName from College where CollegeName like 'a__';

--Find the names ending with 's'


Select CollegeName from College where CollegeName like '%s';

--Find the name of college/students whose name starts with 's' or


whose name ends with 'e'
Select CollegeName from College where CollegeName like 's%' or
CollegeName like '%e';

--Group by Major
Select count(*) as TotalNo from College group by Major;

--Find the average grade by each Major


Select avg(Grade) as AverageGrade, Major from College group by Major;

10
--Find the average grade by each Major having Avg Grade greater than 2
Select avg(Grade) as AverageGrade, Major from College group by Major
having avg(grade)>2;

--Find the name of college with highest grade


Select CollegeName from College where Grade=(Select max(Grade) from
College);

--Find the name of college whose name starts with b


Select CollegeName from College where CollegeName like 'b%';

11
LAB 5
CREATE TABLE PATIENTS(
PatientID int PRIMARY KEY,
PatientName varchar(50),
Address varchar(50),
Age int,
Gender varchar(50)
);

CREATE TABLE HOSPITALS(


PatientID int,
DoctorID int,
HospitalName varchar(50),
Location varchar(50)
);

Insert DOCTORS values(01, 'Vinay', 'Dermatologist', 'Buddhanagar',


80000);
Insert DOCTORS values(02, 'Suneet', 'Dentist', 'Sinamangal', 75000);
Insert DOCTORS values(03, 'Vatty', 'Neurologist', 'Buddhanagar',
69000);
Insert DOCTORS values(04, 'Aish', 'Gastroenterologist', 'Dallu',
50000);
Select *from DOCTORS;

12
Insert PATIENTS values(42, 'Kirtan', 'Buddhanagar', 20, 'Male');
Insert PATIENTS values(43, 'Samwek', 'Patan' , 20, 'Male');
Insert PATIENTS values(44, 'Kapil', 'Baneshwor', 21, 'Male');
Insert PATIENTS values(45, 'Isha', 'Pimbahal' , 21, 'Female');

Select *from PATIENTS;

Insert HOSPITALS values(42, 03, 'Pulse Neuro Center', 'Kathmandu');


Insert HOSPITALS values(43, 01, 'Nepal Korea Skin Hospital',
'Kathmandu');
Insert HOSPITALS values(45, 02, 'Teaching Hospital', 'Kathmandu');
Insert HOSPITALS values(44, 04, 'Biratnagar Hospital', 'Biratnagar');

SELECT *from HOSPITALS;

--Find the name of the doctors whose salaries are greater than average
salary of doctors.

Select DoctorName from DOCTORS


where Salary > (Select avg(Salary) from DOCTORS);

--Remove the record of patient with Patient ID = 44.

13
Delete from PATIENTS
where PatientID = 44;

Before Removal After Removal

--Find the name of doctor who do not work in Teaching Hospital

Select DoctorName from DOCTORS


Full Join HOSPITALS
ON DOCTORS.DoctorID = HOSPITALS.DoctorID
where HospitalName <> 'Teaching Hospital';

--Display ID of patients admitted to hospital of Biratnagar and whose


name contains exactly 3 characters

Select PATIENTS.PatientID from PATIENTS


FULL JOIN HOSPITALS
ON PATIENTS.PatientID = HOSPITALS.PatientID
where Location = 'Biratnagar' and
PatientName like '___';

--Increase the salary of doctors by 12% who works in Neurologist


department.

UPDATE DOCTORS
Set Salary = Salary * 1.12
where Department = 'Neurologist';

14
Before Update

After Update

15

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy