Bird
Raised Fist0
DBMS Theoryknowledge~10 mins

DML (INSERT, UPDATE, DELETE) in DBMS Theory - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - DML (INSERT, UPDATE, DELETE)
Start
↓
Choose DML Operation
↓
INSERT
↓
Add new
↓
rows
↓
Commit
↓
End
The flow starts by choosing one of the three DML operations: INSERT to add rows, UPDATE to modify existing rows, or DELETE to remove rows, then commits the changes.
Execution Sample
DBMS Theory
INSERT INTO students (id, name) VALUES (1, 'Alice');
UPDATE students SET name = 'Alicia' WHERE id = 1;
DELETE FROM students WHERE id = 1;
This code adds a student named Alice, changes her name to Alicia, then removes her record.
Analysis Table
StepOperationCondition/ValuesActionResult
1INSERTid=1, name='Alice'Add new rowRow with id=1 added
2UPDATEWHERE id=1Change name to 'Alicia'Row with id=1 updated
3DELETEWHERE id=1Remove rowRow with id=1 deleted
4END--No more operations
💡 All DML operations executed; no more commands to process.
State Tracker
Table 'students'StartAfter Step 1After Step 2After Step 3
Rowsempty[{id:1, name:'Alice'}][{id:1, name:'Alicia'}]empty
Key Insights - 3 Insights
Why does the UPDATE operation only change the row with id=1?
Because the WHERE clause specifies id=1, so only rows matching this condition are updated, as shown in execution_table step 2.
What happens if DELETE has no WHERE clause?
All rows in the table would be deleted, removing all data, unlike step 3 where only id=1 is deleted.
Does INSERT overwrite existing rows?
No, INSERT adds new rows; it does not modify or remove existing rows, as seen in step 1 where a new row is added.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the new name of the student with id=1?
AAlicia
BAlice
CAlison
DNone
💡 Hint
Check the 'Result' column in execution_table row for step 2.
At which step does the table become empty again?
AStep 1
BStep 3
CStep 2
DNever
💡 Hint
Look at variable_tracker for 'Rows' after each step.
If the DELETE command had no WHERE clause, how would the variable_tracker change after step 3?
ARows would still contain the updated row
BRows would have multiple copies of the row
CRows would be empty
DRows would contain only the original inserted row
💡 Hint
Deleting without WHERE removes all rows, so variable_tracker 'Rows' would be empty.
Concept Snapshot
DML commands modify data in tables:
- INSERT adds new rows
- UPDATE changes existing rows matching conditions
- DELETE removes rows matching conditions
Always use WHERE in UPDATE/DELETE to target specific rows
Changes affect table data immediately after execution
Full Transcript
This visual execution shows how DML commands INSERT, UPDATE, and DELETE work step-by-step. First, INSERT adds a new row with id=1 and name 'Alice'. Then UPDATE changes the name to 'Alicia' for the row where id=1. Finally, DELETE removes the row where id=1. The variable tracker shows the table's state after each step, starting empty, then containing the inserted row, then the updated row, and finally empty again after deletion. Key points include the importance of WHERE clauses to target rows and that INSERT adds rows without overwriting. The quiz checks understanding of these changes by referencing the execution table and variable tracker.

Practice

(1/5)
1. Which DML command is used to add new rows to a database table?
easy
A. INSERT
B. UPDATE
C. DELETE
D. SELECT

Solution

  1. Step 1: Understand the purpose of DML commands

    DML commands are used to manipulate data in tables: adding, changing, or removing rows.
  2. Step 2: Identify the command for adding rows

    The INSERT command adds new rows, UPDATE changes existing rows, and DELETE removes rows.
  3. Final Answer:

    INSERT -> Option A
  4. Quick Check:

    Add new rows = INSERT [OK]
Hint: Add new data? Use INSERT command [OK]
Common Mistakes:
  • Confusing UPDATE with INSERT
  • Using DELETE to add data
  • Thinking SELECT adds data
2. Which of the following is the correct syntax to update the salary to 5000 for employee with id 10?
easy
A. UPDATE employees SET salary 5000 WHERE id = 10;
B. UPDATE employees salary = 5000 WHERE id = 10;
C. UPDATE employees SET salary = 5000 WHERE id = 10;
D. UPDATE employees SET salary = 5000;

Solution

  1. Step 1: Recall the UPDATE syntax

    The correct syntax is UPDATE table_name SET column = value WHERE condition; to update specific rows.
  2. Step 2: Check each option

    UPDATE employees SET salary = 5000 WHERE id = 10; matches the correct syntax with a WHERE clause to target employee id 10. Options B and C miss the SET keyword or equal sign. UPDATE employees SET salary = 5000; lacks WHERE, so it updates all rows.
  3. Final Answer:

    UPDATE employees SET salary = 5000 WHERE id = 10; -> Option C
  4. Quick Check:

    UPDATE with SET and WHERE = UPDATE employees SET salary = 5000 WHERE id = 10; [OK]
Hint: UPDATE needs SET and WHERE for specific rows [OK]
Common Mistakes:
  • Omitting SET keyword
  • Missing WHERE clause
  • Wrong assignment syntax
3. Consider the table products with columns id, name, and price. What will be the result of this query?
DELETE FROM products WHERE price < 100;
medium
A. All products with price greater than 100 will be removed.
B. All products with price less than 100 will be removed.
C. No products will be removed because condition is incorrect.
D. Syntax error due to missing semicolon.

Solution

  1. Step 1: Understand DELETE with WHERE condition

    The DELETE command removes rows matching the WHERE condition. Here, it targets rows where price is less than 100.
  2. Step 2: Analyze the condition and syntax

    The condition price < 100 correctly selects products priced below 100. The semicolon is optional in many systems but good practice.
  3. Final Answer:

    All products with price less than 100 will be removed. -> Option B
  4. Quick Check:

    DELETE with price < 100 removes matching rows [OK]
Hint: DELETE removes rows matching WHERE condition [OK]
Common Mistakes:
  • Confusing less than with greater than
  • Thinking DELETE needs all rows
  • Assuming syntax error without semicolon
4. Identify the error in this SQL statement:
UPDATE employees SET salary = 6000 WHERE;
medium
A. Missing condition after WHERE clause.
B. Incorrect use of SET keyword.
C. Salary value should be in quotes.
D. UPDATE cannot be used without DELETE.

Solution

  1. Step 1: Check the UPDATE statement structure

    UPDATE requires SET to assign new values and WHERE to specify which rows to update.
  2. Step 2: Identify the error in the WHERE clause

    The statement ends with WHERE but no condition follows, which is a syntax error.
  3. Final Answer:

    Missing condition after WHERE clause. -> Option A
  4. Quick Check:

    WHERE must have a condition [OK]
Hint: WHERE must always have a condition [OK]
Common Mistakes:
  • Leaving WHERE empty
  • Putting value in quotes unnecessarily
  • Confusing UPDATE with DELETE
5. You want to increase the price by 10% for all products priced below 50. Which SQL statement correctly does this?
hard
A. UPDATE products SET price = price + 0.10 WHERE price < 50;
B. UPDATE products SET price = price + 10 WHERE price < 50;
C. UPDATE products SET price = price * 0.10 WHERE price < 50;
D. UPDATE products SET price = price * 1.10 WHERE price < 50;

Solution

  1. Step 1: Understand the requirement to increase price by 10%

    Increasing by 10% means multiplying the current price by 1.10 (100% + 10%).
  2. Step 2: Analyze each option

    UPDATE products SET price = price * 1.10 WHERE price < 50; correctly multiplies price by 1.10 for prices less than 50. UPDATE products SET price = price + 10 WHERE price < 50; adds 10 units, not 10%. UPDATE products SET price = price * 0.10 WHERE price < 50; multiplies by 0.10, reducing price. UPDATE products SET price = price + 0.10 WHERE price < 50; adds 0.10 units, a small increase.
  3. Final Answer:

    UPDATE products SET price = price * 1.10 WHERE price < 50; -> Option D
  4. Quick Check:

    Multiply price by 1.10 to increase by 10% [OK]
Hint: Multiply by 1.10 to increase by 10% [OK]
Common Mistakes:
  • Adding fixed amount instead of percentage
  • Multiplying by 0.10 reduces price
  • Forgetting WHERE clause
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard