0
0
MySQLquery~5 mins

Why DML operations modify data in MySQL

Choose your learning style9 modes available
Introduction

DML operations change the data stored in a database. They let you add, update, or remove information to keep it correct and useful.

When you want to add new customer details to a sales database.
When you need to update the price of a product in an inventory list.
When you want to delete old records that are no longer needed.
When you want to correct a mistake in stored data.
When you want to keep the database information current and accurate.
Syntax
MySQL
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
UPDATE table_name SET column1 = value1 WHERE condition;
DELETE FROM table_name WHERE condition;
DML stands for Data Manipulation Language.
These commands change data but do not change the database structure.
Examples
Adds a new employee named Alice who is 30 years old.
MySQL
INSERT INTO employees (name, age) VALUES ('Alice', 30);
Changes Alice's age to 31.
MySQL
UPDATE employees SET age = 31 WHERE name = 'Alice';
Removes Alice's record from the employees table.
MySQL
DELETE FROM employees WHERE name = 'Alice';
Sample Program

This example creates a table, adds a record, updates it, shows the data, deletes the record, and shows the table again.

MySQL
CREATE TABLE employees (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), age INT);
INSERT INTO employees (name, age) VALUES ('Bob', 25);
UPDATE employees SET age = 26 WHERE name = 'Bob';
SELECT * FROM employees;
DELETE FROM employees WHERE name = 'Bob';
SELECT * FROM employees;
OutputSuccess
Important Notes

Always use WHERE clause in UPDATE and DELETE to avoid changing all rows by mistake.

DML commands can be rolled back if your database supports transactions.

Summary

DML commands change the actual data inside tables.

Use INSERT to add, UPDATE to change, and DELETE to remove data.

These operations keep your database information accurate and useful.