Beginner LevelSQL & MySQL
How do INSERT, UPDATE, and DELETE DML operations modify relational tables?
❓ Interview Prompt: Explain Data Manipulation Language (DML), INSERT INTO statements, UPDATE syntax, DELETE filtering, and dangerous un-filtered operations.
Data Manipulation Language (DML) statements alter database records:
3 DML Operations:
1
'INSERT INTO': Inserts new rows into a table ('INSERT INTO table (cols...) VALUES (...)').
2
'UPDATE': Modifies column values for matching rows ('UPDATE table SET col = val WHERE condition').
3
'DELETE FROM': Removes rows matching a condition ('DELETE FROM table WHERE condition').
•
⚠️ WARNING: Omitting the 'WHERE' clause in 'UPDATE' or 'DELETE' modifies or deletes ALL rows in the table!
Code Implementation Example
sql
-- Safe UPDATE with WHERE filter clause
UPDATE users
SET status = 'INACTIVE', updated_at = NOW()
WHERE last_login < '2025-01-01';
-- Safe DELETE with WHERE filter clause
DELETE FROM sessions
WHERE expires_at < NOW();💡Modifying and deleting table rows safely using WHERE clauses.
🎯 Interview Key Takeaway
Always include a WHERE clause when executing UPDATE and DELETE operations to prevent accidental mass table data loss.
#SQL#DML#INSERT#UPDATE#DELETE#Beginner
Back to all SQL & MySQL Questions→