0% found this document useful (0 votes)
72 views37 pages

Dbms Unit 2 r22 and r18 Notes For Dbms

The document provides an overview of the relational model in database management systems, detailing concepts such as tuples, attributes, and relational keys. It explains various relational operations including select, project, union, intersection, and join operations, along with examples for clarity. Additionally, it discusses integrity constraints that ensure data quality and integrity within databases.

Uploaded by

sushu161
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views37 pages

Dbms Unit 2 r22 and r18 Notes For Dbms

The document provides an overview of the relational model in database management systems, detailing concepts such as tuples, attributes, and relational keys. It explains various relational operations including select, project, union, intersection, and join operations, along with examples for clarity. Additionally, it discusses integrity constraints that ensure data quality and integrity within databases.

Uploaded by

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

lOMoARcPSD|52909623

DBMS UNIT-2 - R22 and R18 notes for DBMS

Database Management System (Jawaharlal Nehru Technological University,


Hyderabad)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Kammari Sushma ([email protected])
lOMoARcPSD|52909623

UNIT-2

Relational Model concept

Relational model can represent as a table with columns and rows. Each row is known as a
tuple. Each table of the column has a name or attribute.

Domain: It contains a set of atomic values that an attribute can take.

Attribute: It contains the name of a column in a particular table. Each attribute Ai must have a
domain, dom(Ai)

Relational instance: In the relational database system, the relational instance is represented by a
finite set of tuples. Relation instances do not have duplicate tuples.

Relational schema: A relational schema contains the name of the relation and name of all
columns or attributes.

Relational key: In the relational key, each row has one or more attributes. It can identify the row
in the relation uniquely.

Example: STUDENT Relation

NAME ROLL_NO PHONE_NO ADDRESS AGE

Ram 14795 7305758992 Noida 24

Shyam 12839 9026288936 Delhi 35

Laxman 33289 8583287182 Gurugram 20

Mahesh 27857 7086819134 Ghaziabad 27

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Ganesh 17282 9028 9i3988 Delhi 40

o In the given table, NAME, ROLL_NO, PHONE_NO, ADDRESS, and AGE are the
attributes.

o The instance of schema STUDENT has 5 tuples.

o t3 = <Laxman, 33289, 8583287182, Gurugram, 20>

Properties of Relations

o Name of the relation is distinct from all other relations.

o Each relation cell contains exactly one atomic (single) value

o Each attribute contains a distinct name

o Attribute domain has no significance

o tuple has no duplicate value

o Order of tuple can have a different sequence

Relational Algebra

Relational algebra is a procedural query language. It gives a step by step process to obtain the
result of the query. It uses operators to perform queries.

Types of Relational operation

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

1. Select Operation:

o The select operation selects tuples that satisfy a given predicate.

o It is denoted by sigma (σ).

Notation: σ p(r)

Where:

σ is used for selection prediction


r is used for relation
p is used as a propositional logic formula which may use connectors like: AND OR and NOT.
These relational can use as relational operators like =, ≠, ≥, <, >, ≤.

For example: LOAN Relation

BRANCH_NAME LOAN_NO AMOUNT

Downtown L-17 1000

Redwood L-23 2000

Perryride L-15 1500

Downtown L-14 1500

Mianus L-13 500

Roundhill L-11 900

Perryride L-16 1300

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Input:

σ BRANCH_NAME="perryride" (LOAN)

Output:

BRANCH_NAME LOAN_NO AMOUNT

Perryride L-15 1500

Perryride L-16 1300

2. Project Operation:

o This operation shows the list of those attributes that we wish to appear in the result. Rest
of the attributes are eliminated from the table.

o It is denoted by ∏.

Notation: ∏ A1, A2, An (r)

Where

A1, A2, A3 is used as an attribute name of relation r.

Example: CUSTOMER RELATION

NAME STREET CITY

Jones Main Harrison

Smith North Rye

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Hays Main Harrison

Curry North Rye

Johnson Alma Brooklyn

Brooks Senator Brooklyn

Input:

∏ NAME, CITY (CUSTOMER)

Output:

NAME CITY

Jones Harrison

Smith Rye

Hays Harrison

Curry Rye

Johnson Brooklyn

Brooks Brooklyn

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

3. Union Operation:

o Suppose there are two tuples R and S. The union operation contains all the tuples that are
either in R or S or both in R & S.

o It eliminates the duplicate tuples. It is denoted by ∪.

Notation: R ∪ S

A union operation must hold the following condition:

o R and S must have the attribute of the same number.

o Duplicate tuples are eliminated automatically.

Example:

DEPOSITOR RELATION

CUSTOMER_NAME ACCOUNT_NO

Johnson A-101

Smith A-121

Mayes A-321

Turner A-176

Johnson A-273

Jones A-472

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Lindsay A-284

BORROW RELATION

CUSTOMER_NAME LOAN_NO

Jones L-17

Smith L-23

Hayes L-15

Jackson L-14

Curry L-93

Smith L-11

Williams L-17

Input:

∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR)

Output:

CUSTOMER_NAME

Johnson

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Smith

Hayes

Turner

Jones

Lindsay

Jackson

Curry

Williams

Mayes

4. Set Intersection:

o Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in both R & S.

o It is denoted by intersection ∩.

Notation: R ∩ S

Example: Using the above DEPOSITOR table and BORROW table

Input:

∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR)

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Output:

CUSTOMER_NAME

Smith

Jones

5. Set Difference:

o Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in R but not in S.

o It is denoted by intersection minus (-).

Notation: R - S

Example: Using the above DEPOSITOR table and BORROW table

Input:

∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR)

Output:

CUSTOMER_NAME

Jackson

Hayes

Willians

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Curry

6. Cartesian product

o The Cartesian product is used to combine each row in one table with each row in the
other table. It is also known as a cross product.

o It is denoted by X.

Notation: E X D

Example:

EMPLOYEE

EMP_ID EMP_NAME EMP_DEPT

1 Smith A

2 Harry C

3 John B

DEPARTMENT

DEPT_NO DEPT_NAME

A Marketing

B Sales

C Legal

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Input:

1. EMPLOYEE X DEPARTMENT

Output:

EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME

1 Smith A A Marketing

1 Smith A B Sales

1 Smith A C Legal

2 Harry C A Marketing

2 Harry C B Sales

2 Harry C C Legal

3 John B A Marketing

3 John B B Sales

3 John B C Legal

7. Rename Operation:

The rename operation is used to rename the output relation. It is denoted by rho (ρ).

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Example: We can use the rename operator to rename STUDENT relation to STUDENT1.

Join Operations:

A Join operation combines related tuples from different relations, if and only if a given join
condition is satisfied. It is denoted by ⋈.

Example:

EMPLOYEE

EMP_CODE EMP_NAME

101 Stephan

102 Jack

103 Harry

SALARY

EMP_CODE SALARY

101 50000

102 30000

103 25000

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

1. Operation: (EMPLOYEE ⋈ SALARY)

Result:

EMP_CODE EMP_NAME SALARY

101 Stephan 50000

102 Jack 30000

103 Harry 25000

Types of Join operations:

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

1. Natural Join:

o A natural join is the set of tuples of all combinations in R and S that are equal on their
common attribute names.

o It is denoted by ⋈.

Example: Let's use the above EMPLOYEE table and SALARY table:

Input:

1. ∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)

Output:

EMP_NAME SALARY

Stephan 50000

Jack 30000

Harry 25000

2. Outer Join:

The outer join operation is an extension of the join operation. It is used to deal with missing
information.

Example:

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

EMPLOYEE

EMP_NAME STREET CITY

Ram Civil line Mumbai

Shyam Park street Kolkata

Ravi M.G. Street Delhi

Hari Nehru nagar Hyderabad

FACT_WORKERS

EMP_NAME BRANCH SALARY

Ram Infosys 10000

Shyam Wipro 20000

Kuber HCL 30000

Hari TCS 50000

Input:

1. (EMPLOYEE ⋈ FACT_WORKERS)

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Output:

EMP_NAME STREET CITY BRANCH SALARY

Ram Civil line Mumbai Infosys 10000

Shyam Park street Kolkata Wipro 20000

Hari Nehru Hyderabad TCS 50000


nagar

An outer join is basically of three types:

a. Left outer join

b. Right outer join

c. Full outer join

a. Left outer join:

o Left outer join contains the set of tuples of all combinations in R and S that are equal on
their common attribute names.

o In the left outer join, tuples in R have no matching tuples in S.

o It is denoted by ⟕.

Example: Using the above EMPLOYEE table and FACT_WORKERS table

Input:

1. EMPLOYEE ⟕ FACT_WORKERS

EMP_NAME STREET CITY BRANCH SALARY

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Ram Civil line Mumbai Infosys 10000

Shyam Park street Kolkata Wipro 20000

Hari Nehru street Hyderabad TCS 50000

Ravi M.G. Street Delhi NULL NULL

b. Right outer join:

o Right outer join contains the set of tuples of all combinations in R and S that are equal on
their common attribute names.

o In right outer join, tuples in S have no matching tuples in R.

o It is denoted by ⟖.

Example: Using the above EMPLOYEE table and FACT_WORKERS Relation

Input:

1. EMPLOYEE ⟖ FACT_WORKERS

Output:

EMP_NAME BRANCH SALARY STREET CITY

Ram Infosys 10000 Civil line Mumbai

Shyam Wipro 20000 Park street Kolkata

Hari TCS 50000 Nehru street Hyderabad

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Kuber HCL 30000 NULL NULL

c. Full outer join:

o Full outer join is like a left or right join except that it contains all rows from both tables.

o In full outer join, tuples in R that have no matching tuples in S and tuples in S that have
no matching tuples in R in their common attribute name.

o It is denoted by ⟗.

Example: Using the above EMPLOYEE table and FACT_WORKERS table

Input:

1. EMPLOYEE ⟗ FACT_WORKERS

Output:

EMP_NAME STREET CITY BRANCH SALARY

Ram Civil line Mumbai Infosys 10000

Shyam Park street Kolkata Wipro 20000

Hari Nehru street Hyderabad TCS 50000

Ravi M.G. Street Delhi NULL NULL

Kuber NULL NULL HCL 30000

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

3. Equi join:

It is also known as an inner join. It is the most common join. It is based on matched data as per
the equality condition. The equi join uses the comparison operator(=).

Example:

CUSTOMER RELATION

CLASS_ID NAME

1 John

2 Harry

3 Jackson

PRODUCT

PRODUCT_ID CITY

1 Delhi

2 Mumbai

3 Noida

Input:

1. CUSTOMER ⋈ PRODUCT

Output:

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

CLASS_ID NAME PRODUCT_ID CITY

1 John 1 Delhi

2 Harry 2 Mumbai

3 Harry 3 Noida

Integrity Constraints

o Integrity constraints are a set of rules. It is used to maintain the quality of information.

o Integrity constraints ensure that the data insertion, updating, and other processes have to
be performed in such a way that data integrity is not affected.

o Thus, integrity constraint is used to guard against accidental damage to the database.

Types of Integrity Constraint

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

1. Domain constraints

o Domain constraints can be defined as the definition of a valid set of values for an
attribute.

o The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain.

Example:

2. Entity integrity constraints

o The entity integrity constraint states that primary key value can't be null.

o This is because the primary key value is used to identify individual rows in relation and if
the primary key has a null value, then we can't identify those rows.

o A table can contain a null value other than the primary key field.

Example:

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

3. Referential Integrity Constraints

o A referential integrity constraint is specified between two tables.

o In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary
Key of Table 2, then every value of the Foreign Key in Table 1 must be null or be
available in Table 2.

Example:

4. Key constraints

o Keys are the entity set that is used to identify an entity within its entity set uniquely.

o An entity set can have multiple keys, but out of which one key will be the primary key. A
primary key can contain a unique and null value in the relational table.

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Example:

Relational Calculus

There is an alternate way of formulating queries known as Relational Calculus. Relational


calculus is a non-procedural query language. In the non-procedural query language, the user is
concerned with the details of how to obtain the end results. The relational calculus tells what to
do but never explains how to do. Most commercial relational languages are based on aspects of
relational calculus including SQL-QBE and QUEL.

Why it is called Relational Calculus?

It is based on Predicate calculus, a name derived from branch of symbolic language. A predicate
is a truth-valued function with arguments. On substituting values for the arguments, the function
result in an expression called a proposition. It can be either true or false. It is a tailored version of
a subset of the Predicate Calculus to communicate with the relational database.

Many of the calculus expressions involves the use of Quantifiers. There are two types of
quantifiers:

o Universal Quantifiers: The universal quantifier denoted by ∀ is read as for all which
means that in a given set of tuples exactly all tuples satisfy a given condition.

o Existential Quantifiers: The existential quantifier denoted by ∃ is read as for all which
means that in a given set of tuples there is at least one occurrences whose value satisfy a
given condition.

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Before using the concept of quantifiers in formulas, we need to know the concept of Free and
Bound Variables.

A tuple variable t is bound if it is quantified which means that if it appears in any occurrences a
variable that is not bound is said to be free.

Free and bound variables may be compared with global and local variable of programming
languages.

Types of Relational calculus:

1. Tuple Relational Calculus (TRC)

It is a non-procedural query language which is based on finding a number of tuple variables also
known as range variable for which predicate holds true. It describes the desired information
without giving a specific procedure for obtaining that information. The tuple relational calculus
is specified to select the tuples in a relation. In TRC, filtering variable uses the tuples of a
relation. The result of the relation can have one or more tuples.

Notation:

A Query in the tuple relational calculus is expressed as following notation

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

{T | P (T)} or {T | Condition (T)}

Where

T is the resulting tuples

P(T) is the condition used to fetch T.

For example:

{ T.name | Author(T) AND T.article = 'database' }

Output: This query selects the tuples from the AUTHOR relation. It returns a tuple with 'name'
from Author who has written an article on 'database'.

TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃) and
Universal Quantifiers (∀).

For example:

{ R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)}

Output: This query will yield the same result as the previous one.

2. Domain Relational Calculus (DRC)

The second form of relation is known as Domain relational calculus. In domain relational
calculus, filtering variable uses the domain of attributes. Domain relational calculus uses the
same operators as tuple calculus. It uses logical connectives ∧ (and), ∨ (or) and ┓ (not). It uses
Existential (∃) and Universal Quantifiers (∀) to bind the variable. The QBE or Query by example
is a query language related to domain relational calculus.

Notation:

{ a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Where

a1,a2 areattributes
P stands for formula built by inner attributes

For example:

{< article, page, subject > | ∈ javatpoint ∧ subject = 'database'}

Output: This query will yield the article, page, and subject from the relational javatpoint, where
the subject is a database.

SQL Commands

o SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
o SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.

Types of SQL Commands

There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

1. Data Definition Language (DDL)


o DDL changes the structure of the table like creating a table, deleting a table, altering a
table, etc.
o All the command of DDL are auto-committed that means it permanently save all the
changes in the database.

Here are some commands that come under DDL:

o CREATE
o ALTER
o DROP
o TRUNCATE

a. CREATE It is used to create a new table in the database.

Syntax:

CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);

Example:

CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE);

b. DROP: It is used to delete both the structure and record stored in the table.

Syntax

DROP TABLE table_name;

Example

DROP TABLE EMPLOYEE;

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

c. ALTER: It is used to alter the structure of the database. This change could be either to modify
the characteristics of an existing attribute or probably to add a new attribute.

Syntax:

To add a new column in the table

ALTER TABLE table_name ADD column_name COLUMN-definition;

To modify existing column in the table:

ALTER TABLE table_name MODIFY(column_definitions....);

EXAMPLE

ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));

ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));

d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the
table.

Syntax:

TRUNCATE TABLE table_name;

Example:

TRUNCATE TABLE EMPLOYEE;

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

2. Data Manipulation Language(DML)


o DML commands are used to modify the database. It is responsible for all form of changes
in the database.
o The command of DML is not auto-committed that means it can't permanently save all the
changes in the database. They can be rollback.

Here are some commands that come under DML:

o INSERT
o UPDATE
o DELETE

a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a
table.

Syntax:

INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1, value2, value3, .... valueN);

Or

INSERT INTO TABLE_NAME VALUES (value1, value2, value3, .... valueN);

For example:

INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");

b. UPDATE: This command is used to update or modify the value of a column in the table.

Syntax:

UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE CO


NDITION]

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

For example:

UPDATE students
SET User_Name = 'Sonoo'
WHERE Student_Id = '3';

c. DELETE: It is used to remove one or more row from a table.

Syntax:

DELETE FROM table_name [WHERE condition];

For example:

DELETE FROM javatpoint

WHERE Author="Sonoo";

3. Data Control Language(DCL)

DCL commands are used to grant and take back authority from any database user.

Here are some commands that come under DCL:

o Grant
o Revoke

a. Grant: It is used to give user access privileges to a database.

Example

GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;

b. Revoke: It is used to take back permissions from the user.

Example

REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

4. Transaction Control Language(TCL)

TCL commands can only use with DML commands like INSERT, DELETE and UPDATE only.

These operations are automatically committed in the database that's why they cannot be used
while creating tables or dropping them.

Here are some commands that come under TCL:

o COMMIT
o ROLLBACK
o SAVEPOINT

a. Commit: Commit command is used to save all the transactions to the database.

Syntax:

COMMIT;

Example:

DELETE FROM CUSTOMERS

WHERE AGE = 25;


COMMIT;

b. Rollback: Rollback command is used to undo transactions that have not already been saved to
the database.

Syntax:

ROLLBACK;

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Example:

DELETE FROM CUSTOMERS

WHERE AGE = 25;


ROLLBACK;

c. SAVEPOINT: It is used to roll the transaction back to a certain point without rolling back the
entire transaction.

Syntax:

SAVEPOINT SAVEPOINT_NAME;

5. Data Query Language(DQL)

DQL is used to fetch the data from the database.

It uses only one command:

o SELECT

a. SELECT: This is the same as the projection operation of relational algebra. It is used to select
the attribute based on the condition described by WHERE clause.

Syntax:

SELECT expressions

FROM TABLES

WHERE conditions;

For example:

SELECT emp_name FROM employee WHERE age > 20;

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Difference between DDL and DML

A database is a list of related records, and the Database Management System is the most
common way to manage these databases (DBMS). The SQL (Structured Query Language)

Commands are needed to interact with database systems. These SQL commands can be used to
build tables, insert data into tables, remove or drop tables, change tables, and set permissions for
users. We can categorize the SQL commands as DDL, DQL, DCL, and DML.

This article explains the complete overview of DDL and DML languages. The difference
between DDL and DML commands is the most common part of an interview question. The key
distinction is that the DDL command is used to create a database schema, while the DML
command is used to modify the table's existing data. Before making the comparison, we will
first know these SQL commands

What is a DDL command?

DDL stands for Data Definition Language. As the name suggests, the DDL commands help to
define the structure of the databases or schema. When we execute DDL statements, it takes effect
immediately. The changes made in the database using this command are saved permanently
because its commands are auto-committed. The following commands come under DDL
language:

o CREATE: It is used to create a new database and its objects such as table, views,
function, stored procedure, triggers, etc.

o DROP: It is used to delete the database and its objects, including structures, from the
server permanently.
o ALTER: It's used to update the database structure by modifying the characteristics of an
existing attribute or adding new attributes.
o TRUNCATE: It is used to completely remove all data from a table, including their
structure and space allocates on the server.
o RENAME: This command renames the content in the database.

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Why we use DDL commands?

The following are the reasons to use DDL commands:

o It allows us to store shared data in a database.


o It improved integrity due to the data independence feature.
o It will enable multiple users to work on the same databases.
o It improved security efficient data access.

What is a DML command?

It stands for Data Manipulation Language. The DML commands deal with the manipulation of
existing records of a database. It is responsible for all changes that occur in the database. The
changes made in the database using this command can't save permanently because its commands
are not auto-committed. Therefore, changes can be rollback. The following commands come
under DML language:

o SELECT: This command is used to extract information from a table.


o INSERT: It is a SQL query that allows us to add data into a table's row.
o UPDATE: This command is used to alter or modify the contents of a table.
o DELETE: This command is used to delete records from a database table, either
individually or in groups.

Why we use DML commands?

The following are the reasons to use the DML commands:

o It helps users to change the data in a database table.


o It helps users to specify what data is needed.
o It facilitates human interaction with the system.

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Key Differences between DDL and DML Commands

The following points explain the main differences between DDL and DML commands:

o Data Definition Language (DDL) statements describe the structure of a database or


schema. Data Manipulation Language (DML) statements, on the other hand, allow
altering data that already exists in the database.
o We use the DDL commands for creating the database or schema, while DML commands
are used to populate and manipulate the database.
o DDL commands can affect the whole database or table, whereas DML statements only
affect single or multiple rows based on the condition specified in a query.
o Since DDL commands are auto-committed, modifications are permanent and cannot be
reversed. DML statements, on the other hand, are not auto-committed, which means that
modifications are not permanent and can be reversed.

o DML is an imperative and procedural method, whereas DDL is a declarative method.


o The data in DML statements can be filtered with a WHERE clause, while the records in
DDL statements cannot be filtered with a WHERE clause.

DDL vs. DML Comparison

The following comparison chart explains their main differences in a quick manner:

Comparison DDL DML


Basis

Basic It helps us define a database's It allows us to manipulate, i.e.,


structure or schema and deals with retrieve, update, and delete the
how data is stored in the database. data stored in the database.

Downloaded by Kammari Sushma ([email protected])


lOMoARcPSD|52909623

Full-Form The full form of DDL is Data The full form of DML is Data
Definition Language. Manipulation Language.

Categorization The DDL commands have no The DML commands are


further classification. classified as procedural and non-
procedural (declarative) DMLs.

Command uses The commonly used commands The commonly used commands
under DDL language are: under DML language are:
o CREATE o INSERT
o DROP o UPDATE
o ALTER o DELETE
o TRUNCATE o SELECT
o RENAME

Auto-commit DDL commands are auto- DML commands are not auto-
committed, so changes that happen committed, so database changes
in the database will be permanent. are not permanent.

Rollback DDL commands made changes DML commands do not make


permanent; therefore, we cannot changes permanent; therefore,
roll back these statements. rollback is possible for these
statements.

WHERE DDL commands have no use of a The DML statements can use a
clause WHERE clause because here, WHERE clause while
filtration of records is not possible. manipulating data in a database.

Effect The DDL command affects the The DML commands will affect
entire database or table. the single or multiple records
based on the specified condition.

Downloaded by Kammari Sushma ([email protected])

You might also like