You are on page 1of 26

AMITY SCHOOL OF ENGINEERING AND

TECHNOLOGY

DBMS LAB MANUAL

ADVIN MANHAR

EXPERIMENT 1:
What is SQL? Write down the advantages, disadvantages
and application of SQL.
SQL is the standard language for dealing with Relational Databases.
SQL can be used to insert, search, update, and delete database records.
SQL can do lots of other operations, including optimizing and
maintenance of databases. SQL stands for Structured Query language,
pronounced as "S-Q-L" or sometimes as "See-Quel"... Relational
databases like MySQL Database, Oracle, MS SQL Server, Sybase, etc.
use ANSI SQL.

Application of SQL:

 SQL is used as a Data Definition Language (DDL) meaning you


can independently create a database, define its structure, use it and
then discard it when you are done with it
 SQL is also used as a Data Manipulation Language (DML) which
means you can use it for maintaining an already existing database.
SQL is a powerful language for entering data, modifying data and
extracting data with regard to a database
 SQL is also deployed as a Data Control Language (DCL) which
specifies how you can protect your database against corruption and
misuse.
 SQL is extensively used as a Client/Server language to connect the
front-end with the back-end thus supporting the client/server
architecture
 SQL can also be used in the three-tier architecture of a client, an
application server and a database which defines the Internet
architecture.
Advantages of SQL:
SQL has many advantages which makes it popular and highly
demanded. It is a reliable and efficient language used for
communicating with the database. Some advantages of SQL are as
follows:
1. Faster Query Processing –
Large amount of data is retrieved quickly and efficiently. Operations
like Insertion, deletion, manipulation of data is also done in almost
no time.
2. No Coding Skills –
For data retrieval, large number of lines of code is not required. All
basic keywords such as SELECT, INSERT INTO, UPDATE, etc are
used and also the syntactical rules are not complex in SQL, which
makes it a user-friendly language.
3. Standardised Language –
Due to documentation and long establishment over years, it provides
a uniform platform worldwide to all its users.
4. Portable –
It can be used in programs in PCs, server, laptops independent of
any platform (Operating System, etc). Also, it can be embedded
with other applications as per need/requirement/use.
5. Interactive Language –
Easy to learn and understand, answers to complex queries can be
received in seconds.

Disadvantages of SQL:

Although SQL has many advantages, still there are a few disadvantages.
Various Disadvantages of SQL are as follows:
1. Complex Interface –
SQL has a difficult interface that makes few users uncomfortable
while dealing with the database.
2. Cost –
Some versions are costly and hence, programmers cannot access it.
3. Partial Control –
Due to hidden business rules, complete control is not given to the
database

EXPERIMENT 2:
CREATE command
 Use: It is used to create a new database or table in a databaseand
specify the name of the table and column inside it.

 Syntax:
o Create new database –

CREATE DATABASE database_name;

o Create new table in a database –

CREATE TABLE table_name(


COLUMN 1 datatype,
COLUMN 2 datatype,
COLUMN 3 datatype,
... ...
);

 Example:

 Output:
EXPERIMENT 3:
INSERT command
 Use: It is used to add new rows of data to a table in the database.

 Syntax:

INSERT INTO table_nameVALUES(


value 1, value 2, value 3,... ...value n
);

 Example:

 Output:
EXPERIMENT 4:
ALTER command
 Use: It is used to add, delete, or modify columns in an existing
table. The ALTER TABLE statement is also used to add and drop
various constraints on an existing table.

 Syntax:

ALTER TABLE table_name ADD column_name


datatype;

 Example:

 Output:

EXPERIMENT 5:
DELETE command

 Use: It is used toremove the rows from the table.

 Syntax:

DELETE FROM table_name


WHERE some_colum = some_value;

 Example:

 Output:

EXPERIMENT 6:
UPDATE command

 Use: It is used to modify existing records in a table.

 Syntax:

UPDATE table_name SET some_column =


some_value WHERE some_column = some_value;

 Example:

 Output:
EXPERIMENT 7:
DROP command

 Use:It is used toremove a component from a relational database


management system (RDBMS).

 Syntax:

DROP object object_name;

 Example:

DROP TABLE table_name;


table_name: Name of the table to be deleted.

DROP DATABASE database_name;


database_name: Name of the database to be
deleted
EXPERIMENT 8:
TRUNCATE command

 Use: It is used todelete complete data from an existing table. You can
also use DROP TABLE command to delete complete table but it
would remove complete table structure form the database and you
would need to re-create this table once again if you wish you store
some data.
 Syntax:
TRUNCATE TABLE table_name;

 Example:

 Output:
EXPERIMENT 9:
Create a table where table name is Hospital with 4 attributes.
i. Add 8 entries inside a table.
ii. Add two additional columns.
iii. Insert a value in newly added columns.
iv. Delete row no.5 data.
v. Delete column no. 3
vi. Delete all the entries from the table. (use truncate command)
vii. Delete table from the database.

SOURCE CODE:

create table hospital(


patient_id int not null,
patient_namevarchar(50),
patient_phonevarchar(20),
patient_emailvarchar(50),
primary key(patient_id));

insert into hospital values(


1020, "Rajesh", 7511256797, "rajesh@gmail.com"
);
insert into hospital values(
1021, "Sana", 8920256591, "sana25@yahoo.com"
);
insert into hospital values(
1022, "Aashi", 7201256999, "aashi@gmail.com"
);
insert into hospital values(
1023, "Sunidhi", 9611200700, "sunidhi@gmail.com"
);
insert into hospital values(
1024, "Abhi", 9739256790, "abhi77@yahoo.com"
);
insert into hospital values(
1025, "Shubham", 8101256812, "shubham@gmail.com"
);
insert into hospital values(
1026, "Sneha", 6011266700, "sneha@gmail.com"
);
insert into hospital values(
1027, "Yuvraj", 8311256169, "yuvi23@yahoo.com"
);

select * from hospital;

alter table hospital add patient_treatmentvarchar(30);


alter table hospital add patient_medicinevarchar(30);
select * from hospital;

Update hospital set patient_treatment = 'Gastric',


patient_medicine = 'Acemiz' where patient_id=1020;

Update hospital set patient_treatment = 'Stomach pain',


patient_medicine = 'citrizen' where patient_id=1021;

Update hospital set patient_treatment = 'Cold & Fever',


patient_medicine = 'paracetamol' where patient_id=1022;

Update hospital set patient_treatment = 'Headache',


patient_medicine = 'eldoper' where patient_id=1023;

Update hospital set patient_treatment = 'Cold & Cough',


patient_medicine = 'paracetamol' where patient_id=1024;

Update hospital set patient_treatment = 'Blood_clot',


patient_medicine = 'B_complex' where patient_id=1025;

Update hospital set patient_treatment = 'Fever',


patient_medicine = 'paracetmol' where patient_id=1026;
Update hospital set patient_treatment = 'Fracture',
patient_medicine = 'vitamin c & B complex' where
patient_id=1027;

select * from hospital;

delete from hospital where patient_id = 1024;

select * from hospital;


alter table hospital drop column patient_phone;

select * from hospital;

truncate table hospital;

select * from hospital;


drop table hospital;

EXPERIMENT 10:
Create a table where table name is Subject with its attributes (Sub_id,
Sub_name, Sub_depatment, Sub_credit).
 Use alter command and add Sub_faculty and Contact_no.

SOURCE CODE:

create table Subject(


Sub_id int not null,
Sub_namevarchar(30),
Sub_departmentvarchar(30),
Sub_credit int,
Primary Key(Sub_id)
);

insert into Subject values(


1, "APP. MATHS", "ASET", 4
);
insert into Subject values(
2, "DATA STRUCTURES", "ASET", 4
);
insert into Subject values(
3, "DS LAB", "ASET", 2
);
insert into Subject values(
4, "OPERATING SYSTEM", "ASET", 3
);
insert into Subject values(
5, "OS LAB", "ASET", 2
);
insert into Subject values(
6, "DATABASE MANAGEMENT SYSTEM", "ASET", 3
);
insert into Subject values(
7, "DBMS LAB", "ASET", 2
);
insert into Subject values(
8, "DIGITAL ELECTRONICS", "ASET", 3
);
insert into Subject values(
9, "DE LAB", "ASET", 2
);
insert into Subject values(
10, "ENGLISH COMM.", "ASET", 1
);
insert into Subject values(
11, "BEHAVIORAL MANAGEMENT", "ASET", 3
);
insert into Subject values(
12, "FRENCH OF COMM.", "ASET", 2
);
insert into Subject values(
13, "HUMAN VALUE ETHICS", "ASET", 1
);

Select * from Subject;


alter table Subject add(
Sub_facultyvarchar(30),
Contact_no. bigint );

select * from Subject;

update Subject set Sub_faculty = "Mrs. Poonam Mishra",


Contact_no = 8945702289 where sub_id = 1;
update Subject set Sub_faculty = "Mr G Raghavendra Prasad",
Contact_no = 7902156789 where sub_id = 2;

update Subject set Sub_faculty = "Mr G Raghavendra Prasad",


Contact_no = 7001344770 where sub_id = 3;

update Subject set Sub_faculty = "Mr AdvinManhar", Contact_no


= 9181274100 where sub_id = 4;

update Subject set Sub_faculty = "Mr Bakhtawar Ahmed",


Contact_no = 8002114793 where sub_id = 5;

update Subject set Sub_faculty = "Mr AdvinManhar", Contact_no


= 7114789203 where sub_id = 6;

update Subject set Sub_faculty = "Mr AdvinManhar", Contact_no


= 8875289940 where sub_id = 7;

update Subject set Sub_faculty = "Mr Ankit Mishra", Contact_no


= 7882135640 where sub_id = 8;

update Subject set Sub_faculty = "Mr Ankit Mishra", Contact_no


= 9245678901 where sub_id = 9;

update Subject set Sub_faculty = "Mr Arindam Patra",


Contact_no = 8902453789 where sub_id = 10;

update Subject set Sub_faculty = "Dr. Sonali Malewar",


Contact_no = 9821456709 where sub_id = 11;

update Subject set Sub_faculty = "Mr Rajesh Kumar", Contact_no


= 7803567027 where sub_id = 12;
update Subject set Sub_faculty = "Dr.Tarannum Sarwar",
Contact_no = 8900251195 where sub_id = 13;

select * from subject;

EXPERIMENT 11:
Create a table where table name is Subject with its attributes (Sub_id,
Sub_name, Sub_depatment, Sub_credit).

SOURCE CODE:

create table employee(


e_id int not null,
e_namevarchar(30),
e_salary int,
e_addressvarchar(50),
);

insert into employee values(


110, "Rahul", 40000, "Raipur, Chhattisgarh"
);
insert into employee values(
120, "Sanjana", 52000, "Jagdalpur, Chhattisgarh"
);
insert into employee values(
130, "Reetu", 40000, "Bhilai, Chhattisgarh"
);
insert into employee values(
146, "Rohan", 10000, "Durg, Chhattisgarh"
);
insert into employee values(
152, "Manoj", 38000, "Kharora, Chhattisgarh"
);
insert into employee values(
161, "Shubham", 18000, "Rajnandgaon, Chhattisgarh"
);
insert into employee values(
174, "Reetu", 60000, "Raipur, Chhattisgarh"
);
insert into employee values(
186, "Isha", 35000, "Bhilai, Chhattisgarh"
);

Select * from employee;


alter table employee add(
e_mobilebigint,
e_aadharbigint );

select * from employee;

Update employee set e_mobile = 7511256797, e_aadhar =


201053468210 where e_id=110;
Update employee set e_mobile = 8920256591, e_aadhar =
603156789036 where e_id=120;
Update employee set e_mobile = 7201256999, e_aadhar =
543267810400 where e_id=130;
Update employee set e_mobile = 9611200700, e_aadhar =
601057730066 where e_id=146;
Update employee set e_mobile = 9739256790, e_aadhar =
703288479222 where e_id=152;
Update employee set e_mobile = 8101256812, e_aadhar =
800456719245 where e_id=161;
Update employee set e_mobile = 8311256169, e_aadhar =
697166540443 where e_id=174;
Update employee set e_mobile = 6011266700, e_aadhar =
774391380000 where e_id=186;

select * from employee;

select * from employee where e_salary>= 20000;


select e_id, e_name from employee where e_salary>20000;

select e_name from employee


group by e_name having
count(e_name) >1;

You might also like