SQL FOUNDATIONS:Data Manipulation (INSERT, UPDATE, DELETE)
Learn INSERT, UPDATE, and DELETE with safe preview exercises.
SQL Data Manipulation (INSERT, UPDATE, DELETE) Explained with Examples + Practice Questions
When to Use Data Manipulation
- Use INSERT to add new data
- Use UPDATE to modify existing data
- Use DELETE to remove data
These operations are used in:
- Backend systems
- Database management
- Real-world applications
Example Dataset
Table: employees
INSERT (Add Data)
Insert a New Row
sqlINSERT INTO employees (id, name, department, salary)VALUES (4, 'Emma', 'Finance', 70000);
Insert Multiple Rows
sqlINSERT INTO employees (id, name, department, salary)VALUES(5, 'David', 'HR', 45000),(6, 'Ankit', 'IT', 52000);
Key Points:
- Must match column order
- Required columns cannot be NULL
- Always specify column names (best practice)
UPDATE (Modify Data)
Update Specific Row
sqlUPDATE employeesSET salary = 65000WHERE name = 'Alice';
Update Multiple Columns
sqlUPDATE employeesSET department = 'Finance', salary = 70000WHERE id = 3;
Key Points:
- Always use WHERE
- Without WHERE, all rows will be updated
DELETE (Remove Data)
Delete Specific Row
sqlDELETE FROM employeesWHERE id = 2;
Delete Multiple Rows
sqlDELETE FROM employeesWHERE department = 'HR';
Key Points:
- Always use WHERE
- Without WHERE, deletes all rows
INSERT vs UPDATE vs DELETE
Combining with Conditions
sqlUPDATE employeesSET salary = salary + 5000WHERE department = 'IT';
Key Concepts
- INSERT adds data
- UPDATE modifies data
- DELETE removes data
- WHERE is critical to avoid mistakes
Practice Note
For safety, these exercises preview the effect using SELECT queries. When write actions are enabled later, you can swap them to real INSERT/UPDATE/DELETE.
Data Manipulation (INSERT, UPDATE, DELETE) Missions
Solve exercises in sequence to unlock the next mission.
Preview insert Neha + Karan
Insert two employees: (8, 'Neha', 'HR', 42000) and (9, 'Karan', 'Finance', 72000).
Preview update Bob salary
Update salary of employee 'Bob' to 60000.
Preview update department
Update department of employee with id = 1 to 'Finance'.
Preview raise IT salaries
Increase salary of all IT employees by 5000.
Preview delete id 3
Delete employee with id = 3.
Preview delete HR
Delete all employees from HR department.
Preview set NULL salaries to 0
Update salary to 0 where salary is NULL.
Preview insert name + department
Insert employee with only name and department (salary default).
Preview 10 percent raise
Increase salary by 10% for employees earning less than 50000.