You are on page 1of 16

Database Management System Lab (CSP249)

B. TECH 2nd YEAR SEMESTER: 4th

SESSION: 2022-2023

Submitted By:

Viney Chhillar
2021511307

Submitted To:

Dr. Gaurav Raj

Associate Professor

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

School of Engineering and Technology.

SHARDA UNIVERSITY, GREATER NOIDA.


S. N0 Experiment Experiment Submission Teacher
Date Date Remark
Database Management System Lab (CSP249)
B. TECH 2nd YEAR SEMESTER: 4th

SESSION: 2022-2023

Submitted By:

Shreya
2021525002

Submitted To:

Dr. Gaurav Raj

Associate Professor

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

School of Engineering and Technology.

SHARDA UNIVERSITY, GREATER NOIDA.


S. N0 Experiment Experiment Submission Teacher
Date Date Remark
Experiment No:2

Title : Implementation of DML commands of SQL with suitable examples


 Insert table
 Update table
 Delete Table

Objective :
To understand the different issues involved in the design and implementation of a
database system
To understand and use data manipulation language to query, update, and manage a
database

Theory :

DATA MANIPULATION LANGUAGE (DML): The Data Manipulation Language (DML)


is used to retrieve, insert and modify database information. These commands will be used by
all database users during the routine operation of the database. Let's take a brief look at the
basic DML commands:
1. INSERT 2. UPDATE 3. DELETE
1. INSERT INTO: This is used to add records into a relation. These are three type of
INSERT INTO queries which are as

a) Inserting a single record


Syntax: INSERT INTO < relation/table name>
(field_1,field_2……field_n)VALUES(data_1,data_2, data_n);
Example: SQL>INSERT INTO student(sno,sname,class,address)VALUES
(1,’Ravi’,’M.Tech’,’Palakol’);
b) Inserting a single record
Syntax: INSERT INTO < relation/table name>VALUES (data_1,data_2, data_n);
Example: SQL>INSERT INTO student VALUES (1,’Ravi’,’M.Tech’,’Palakol’);
c) Inserting all records from another relation
Syntax: INSERT INTO relation_name_1 SELECT Field_1,field_2,field_n

FROM relation_name_2 WHERE field_x=data;


Example: SQL>INSERT INTO std SELECT sno, sname
FROM student WHERE name = ‘Ramu‘;

d) Inserting multiple records


Syntax: INSERT INTO relation_name field_1, field_2, field_n) VALUES
(&data_1, &data_2, .................. &data_n);
Example: SQL>INSERT INTO student (sno, sname, class,address)VALUES
(&sno,’&sname’,’&class’,’&address’);

Enter value for sno: 101


Enter value for name: Ravi
Enter value for class: M.Tech
Enter value for name: Palakol

2. UPDATE-SET-WHERE: This is used to update the content of a record in a relation.


Syntax: SQL>UPDATE relation name SET
Field_name1=data,field_name2=data,WHERE field_name=data;
Example: SQL>UPDATE student SET sname = ‘kumar’ WHERE sno=1;

3. DELETE-FROM: This is used to delete all the records of a relation but it will retain the
structure of that relation.
a) DELETE-FROM: This is used to delete all the records of relation.
Syntax: SQL>DELETE FROM relation_name;
Example: SQL>DELETE FROM std;
b) DELETE -FROM-WHERE: This is used to delete a selected record from a relation.Syntax:
SQL>DELETE FROM relation_name WHERE condition;
Example: SQL>DELETE FROM student WHERE sno = 2;

5. TRUNCATE: This command will remove the data permanently. But structure will not be
removed.
Difference between Truncate & Delete:-
 By using truncate command data will be removed permanently & will not get back where as by
using delete command data will be removed temporally & get back by using roll back command.
 By using delete command data will be removed based on the condition where as by using
truncate command there is no condition.
 Truncate is a DDL command & delete is a DML command.

Syntax: TRUNCATE TABLE <Table name>


Example TRUNCATE TABLE student;

 To Retrieve data from one or more tables.

1. SELECT FROM: To display all fields for all records. Syntax :


SELECT * FROM relation_name;
Example : SQL> select * from dept;

DEPTNO DNAME LOC


-------- ----------- ----------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

2. SELECT FROM: To display a set of fields for all records of relation.

Syntax: SELECT a set of fields FROM relation_name;


Example: SQL> select deptno, dname from dept;

DEPTNO DNAME

10 ACCOUNTING
20 RESEARCH
30 SALES
3. SELECT - FROM -WHERE: This query is used to display a selected set of fields for aselected
set of records of a relation.

Syntax: SELECT a set of fields FROM relation_name WHERE condition;


Example: SQL> select * FROM dept WHERE deptno<=20;

DEPTNO DNAME LOC


------ ----------- ------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS

Sample Case For Student Record

Create Table Student (sno NUMBER (3), sname CHAR (10), class CHAR (5));
ALTER TABLE Student ADD (Address CHAR(10));
Desc Student;
INSERT INTO Student (sno,sname,class,address) VALUES ('1', 'Gaurav', 'BTECH', 'NOIDA');
INSERT INTO Student (sno,sname,class,address) VALUES ('2', 'Ramesh', 'BSC', 'Jalandhar');
INSERT INTO Student (sno,sname,class,address) VALUES ('3', 'Parveen', 'MCA', 'SriNagar');
INSERT INTO Student (sno,sname,class,address) VALUES ('4', 'Rohan', 'BCA', 'GrNoida');
INSERT INTO Student (sno,sname,class,address) VALUES ('5', 'Shahid', 'MTECH', 'Aligarh');
Select * From Student;
Select * From Student where Address = 'NOIDA';
Experiment No:2

Title : Implementation of DML commands of SQL with suitable examples


 Insert table
 Update table
 Delete Table

Objective :
To understand the different issues involved in the design and implementation of a
database system
To understand and use data manipulation language to query, update, and manage a
database

Theory :

DATA MANIPULATION LANGUAGE (DML): The Data Manipulation Language (DML)


is used to retrieve, insert and modify database information. These commands will be used by
all database users during the routine operation of the database. Let's take a brief look at the
basic DML commands:
1. INSERT 2. UPDATE 3. DELETE
4. INSERT INTO: This is used to add records into a relation. These are three type of
INSERT INTO queries which are as

e) Inserting a single record


Syntax: INSERT INTO < relation/table name>
(field_1,field_2……field_n)VALUES(data_1,data_2, data_n);
Example: SQL>INSERT INTO student(sno,sname,class,address)VALUES
(1,’Ravi’,’M.Tech’,’Palakol’);
f) Inserting a single record
Syntax: INSERT INTO < relation/table name>VALUES (data_1,data_2, data_n);
Example: SQL>INSERT INTO student VALUES (1,’Ravi’,’M.Tech’,’Palakol’);
g) Inserting all records from another relation
Syntax: INSERT INTO relation_name_1 SELECT Field_1,field_2,field_n

FROM relation_name_2 WHERE field_x=data;


Example: SQL>INSERT INTO std SELECT sno, sname
FROM student WHERE name = ‘Ramu‘;

h) Inserting multiple records


Syntax: INSERT INTO relation_name field_1, field_2, field_n) VALUES
(&data_1, &data_2, .................. &data_n);
Example: SQL>INSERT INTO student (sno, sname, class,address)VALUES
(&sno,’&sname’,’&class’,’&address’);

Enter value for sno: 101


Enter value for name: Ravi
Enter value for class: M.Tech
Enter value for name: Palakol

5. UPDATE-SET-WHERE: This is used to update the content of a record in a relation.


Syntax: SQL>UPDATE relation name SET
Field_name1=data,field_name2=data,WHERE field_name=data;
Example: SQL>UPDATE student SET sname = ‘kumar’ WHERE sno=1;

6. DELETE-FROM: This is used to delete all the records of a relation but it will retain the
structure of that relation.
c) DELETE-FROM: This is used to delete all the records of relation.
Syntax: SQL>DELETE FROM relation_name;
Example: SQL>DELETE FROM std;
d) DELETE -FROM-WHERE: This is used to delete a selected record from a relation.Syntax:
SQL>DELETE FROM relation_name WHERE condition;
Example: SQL>DELETE FROM student WHERE sno = 2;

6. TRUNCATE: This command will remove the data permanently. But structure will not be
removed.
Difference between Truncate & Delete:-
 By using truncate command data will be removed permanently & will not get back where as by
using delete command data will be removed temporally & get back by using roll back command.
 By using delete command data will be removed based on the condition where as by using
truncate command there is no condition.
 Truncate is a DDL command & delete is a DML command.

Syntax: TRUNCATE TABLE <Table name>


Example TRUNCATE TABLE student;

 To Retrieve data from one or more tables.

4. SELECT FROM: To display all fields for all records. Syntax :


SELECT * FROM relation_name;
Example : SQL> select * from dept;

DEPTNO DNAME LOC


-------- ----------- ----------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

5. SELECT FROM: To display a set of fields for all records of relation.

Syntax: SELECT a set of fields FROM relation_name;


Example: SQL> select deptno, dname from dept;

DEPTNO DNAME

10 ACCOUNTING
20 RESEARCH
30 SALES
6. SELECT - FROM -WHERE: This query is used to display a selected set of fields
for aselected set of records of a relation.

Syntax: SELECT a set of fields FROM relation_name WHERE condition;


Example: SQL> select * FROM dept WHERE deptno<=20;

DEPTNO DNAME LOC


------ ----------- ------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS

Sample Case For Student Record

Create Table Student (sno NUMBER (3), sname CHAR (10), class
CHAR (5));ALTER TABLE Student ADD (Address CHAR(10));
Desc Student;
INSERT INTO Student (sno,sname,class,address) VALUES ('1', 'Gaurav', 'BTECH',
'NOIDA');INSERT INTO Student (sno,sname,class,address) VALUES ('2',
'Ramesh', 'BSC', 'Jalandhar'); INSERT INTO Student (sno,sname,class,address)
VALUES ('3', 'Parveen', 'MCA', 'SriNagar'); INSERT INTO Student
(sno,sname,class,address) VALUES ('4', 'Rohan', 'BCA', 'GrNoida'); INSERT INTO
Student (sno,sname,class,address) VALUES ('5', 'Shahid', 'MTECH', 'Aligarh');
Select * From Student;
Select * From Student where Address = 'NOIDA';

You might also like