0% found this document useful (0 votes)
9 views27 pages

DML Presentation

DML, or Data Manipulation Language, is a subset of SQL used to interact with and modify data in databases, allowing users to retrieve, insert, update, and delete records. Key DML commands include SELECT, INSERT, UPDATE, and DELETE, which are essential for maintaining data consistency and integrity. Transactions in DML ensure that multiple operations are treated as a single action, enhancing data reliability and allowing for partial rollbacks with SAVEPOINT.

Uploaded by

Jojo Bugarin
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)
9 views27 pages

DML Presentation

DML, or Data Manipulation Language, is a subset of SQL used to interact with and modify data in databases, allowing users to retrieve, insert, update, and delete records. Key DML commands include SELECT, INSERT, UPDATE, and DELETE, which are essential for maintaining data consistency and integrity. Transactions in DML ensure that multiple operations are treated as a single action, enhancing data reliability and allowing for partial rollbacks with SAVEPOINT.

Uploaded by

Jojo Bugarin
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/ 27

Introduction to DML

DML stands for Data Manipulation Language. It is a part of SQL that allows
us to interact with and modify the data inside a database. DML helps us add,
update, retrieve, or remove files from it.

DML is used to:

● Retrieved data
● Insert new records
● Update existing records
● Delete unwanted records
The primary DML commands include:

● SELECT - Retrieves data from one or more tables.


● INSERT - Adds new records into a table.
● UPDATE - Modifies existing records in a table.
● DELETE - Removes records from a table.
Purpose of DML

DML is essential for interacting with the data stored in a database, enabling
users to modify existing records and maintain data consistency. Without DML, a
database would be just a static collection of information. DML makes it dynamic,
allowing users to manage data efficiently in real-time.

For example:

● In a banking system, DML helps update account balances after a transaction.


● In an e-commerce website, DML is used to insert new orders and update
product availability.
Impact of DML Operations on Databases

Since DML modifies data, it has a direct impact on how databases perform and
function. Key effects:

1. Data Modification and Maintenance

● DML allows users to update records, ensuring information stays relevant and
accurate.

2. Transaction Control

● Operations like COMMIT (to save changes) and ROLLBACK (to undo changes)
help maintain data integrity.
3. Performance Considerations

● Too many DML operations can slow down a database, especially with large
datasets. Optimization is needed

4. Concurrency Control

● When multiple users modify data at the same time, databases ensure that no
conflicts occur.

5. Data Integrity and Security

● DML works alongside constraints (like PRIMARY KEY and FOREIGN KEY) to
maintain accuracy and prevent unauthorized changes.
Inserting Data into Tables

● INSERT INTO Syntax:


- Used to add new records to a table.

Syntax: INSERT INTO table_name (column1, column2) VALUES


(value1, value2);
Inserting Single and Multiple Rows:
- Single Row: INSERT INTO students (column1, column2, column3, column 4)
VALUES (values1, values2, values3, values4);
MULTIPLE ROWS:INSERT INTO table_name (column1, column2,
column3, column4...) VALUES (value1a, value2a, value3a, ...), (value1b,
value2b, values3b, value4b ...), (value1c, value2c, value3c, ...);
Inserting Data with Specific Columns:

- You can specify only necessary columns to insert data.


EXAMPLES:
EXAMPLES:
Using DEFAULT Values:
- If a column has a default value, you can use DEFAULT keyword during
insertion.
Updating Existing Data

● UPDATE Statement Syntax:


● The UPDATE statement is used to modify the existing records in a table.
UPDATE Syntax:

table_name:
● The name of the table where you want to update the data.
column1 = value1, column2 = value2, …:
● Specifies the columns you want to modify and their new values.
WHERE condition:
● Specifies the conditions that determine which rows to update.
Using WHERE to Target Specific Records

The WHERE clause ensures that only specific records are updated.
Updating Multiple Rows at Once:

You can update multiple rows with a single statement by using conditions in the
WHERE clause.
Importance of Careful Updates to Avoid
Accidental Changes:
The importance of careful updates to avoid accidental changes can be
understood through proper UPDATE syntax
Deleting Data from Tables

● DELETE Statement Syntax:


- When working with databases, you may need to delete data from tables. SQL provide different
ways to remove data, including DELETE and TRUNCATE statements.

Syntax: DELETE FROM table_name;


Deleting Data from Tables
● Using WHERE to Delete Specific Records:
-Using the WHERE clause ensures that only specific records are deleted instead of
removing all data.

Syntax: DELETE FROM table_name WHERE condition;


Deleting Data from Tables

Example Syntax: DELETE FROM students WHERE course = ‘Computer Science’ ;


Deleting Data from Tables
● Difference Between DELETE and TRUNCATE:
- DELETE removes specific rows or maintain logs and can be rolled back.

DELETE FROM students;


Deleting Data from Tables

● Difference Between DELETE and TRUNCATE:


- TRUNCATE removes all data quickly and cannot be undone.
TRUNCATE TABLE students;
Using Transactions in DML

Imagine you're making several changes to a spreadsheet – maybe


updating prices, adding new items, and deleting old ones. A database
transaction is like grouping all those changes together.

Concept of Transactions:
● A transaction is a bunch of database commands (like adding,
changing, or removing data) that are treated as one single action.
Either all the commands succeed, or none of them do. This is
important because it keeps the data consistent and reliable.
Ensuring Data Integrity:
Think about transferring money between bank accounts. You wouldn't want the
money to be taken from one account but not added to the other. Transactions prevent
this. If any part of the transaction fails, the entire thing is undone, keeping everything
consistent.

Using SAVEPOINT for Partial Rollbacks:


Sometimes, you might realize you made a mistake halfway through your
spreadsheet changes. A SAVEPOINT is like creating a backup point. If something
goes wrong later, you can go back to that backup instead of undoing everything.
This lets you undo only part of a transaction, keeping the rest of the changes.
START TRANSACTION;

We begin our group changes.


We change employee 1’s age to 25
ROLLBACK;

In short, transactions are like a safety net for your database changes. They make
sure everything is consistent and reliable. SAVEPOINT gives you even more control
by letting you undo only parts of a transaction.

You might also like