Skip to content
Computer ScienceCBSE Class 12 · Structured Query Language (SQL)

INSERT, UPDATE and DELETE in SQL: Changing the Data of a Table (Class 12 Computer Science)

Updated 17 October 2026 · Fact-checked

INSERT INTO adds a new row, UPDATE ... SET changes values in existing rows, and DELETE FROM removes rows. UPDATE and DELETE act on every row unless a WHERE clause limits them, so the condition must always be written when only some rows are meant.

INSERT adds a row, UPDATE edits values, DELETE removes rows; UPDATE and DELETE hit every row unless WHERE limits them.

Illustration drawn for QuestionBuddy.

Understand INSERT, UPDATE and DELETE Commands

These three DML commands change the data of a table. The examples use the EMPLOYEE table of the chapter, which has the columns EmpID, Name, DeptID, Salary, City and DOJ.

INSERT INTO. Adds one row.

INSERT INTO EMPLOYEE VALUES ('E07', 'Neha Jain', 'D4', 47000, 'Pune', '2024-01-08');
INSERT INTO EMPLOYEE (EmpID, Name, DeptID) VALUES ('E08', 'Tara Nair', 'D2');
  • Without a column list, give a value for every column in table order.
  • With a column list, only those columns get values; the others become NULL (or their default) unless a NOT NULL or PRIMARY KEY constraint forbids it.
  • Text and dates go in single quotes; numbers do not. A date is 'YYYY-MM-DD'.
  • A PRIMARY KEY value that already exists (a duplicate EmpID) is rejected.

UPDATE ... SET. Changes values in existing rows.

UPDATE EMPLOYEE SET Salary = Salary + 5000 WHERE DeptID = 'D1';
UPDATE EMPLOYEE SET Salary = 40000, City = 'Pune' WHERE EmpID = 'E05';

More than one column can be set, separated by commas. The right side may be an expression using the old value. Without WHERE, every row is updated. A NULL stays NULL after arithmetic (NULL + 5000 is NULL).

DELETE FROM. Removes whole rows (the table structure stays).

DELETE FROM EMPLOYEE WHERE City = 'Mumbai';
DELETE FROM EMPLOYEE;

The second statement, without WHERE, deletes all rows but keeps the empty table. DROP TABLE (DDL) is what removes the table itself.

Effect on degree and cardinality. INSERT raises the cardinality; DELETE lowers it; UPDATE changes neither. None of them changes the degree.

INSERT, UPDATE and DELETE Commands: key facts

INSERT
  • INSERT INTO table VALUES (all values in order)
  • INSERT INTO table (cols) VALUES (values)
  • Text and dates in single quotes
  • Missing columns become NULL
A duplicate primary key is rejected.
UPDATE
  • UPDATE table SET col = value [, col = value] WHERE condition
  • Without WHERE all rows change
  • NULL plus a number stays NULL
Add WHERE to limit the change.
DELETE
  • DELETE FROM table WHERE condition
  • Without WHERE all rows are deleted
  • The table structure remains
DROP TABLE removes the table.
Effect on the table
INSERTcardinality plus 1 per row
DELETEcardinality minus the rows removed
UPDATEno change to degree or cardinality
Degree changes only through ALTER TABLE.

How to answer INSERT, UPDATE and DELETE Commands questions

For a DML tracing question, apply one statement at a time to the current state of the table.

  1. 1Write the current table or list the affected columns before starting.
  2. 2For INSERT, add the row and note the new count; check the primary key is not repeated.
  3. 3For UPDATE, find the rows that satisfy WHERE (NULL never satisfies a comparison) and compute the new values.
  4. 4For DELETE, remove all rows that satisfy WHERE; without WHERE remove all rows.
  5. 5Re-count the rows or recompute the sum only at the end, from the final table.
  6. 6Write the answer in the form the query asks for (count, sum, list of rows).

INSERT, UPDATE and DELETE Commands in real life

The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Giving a raise to one department

Suppose a company decides to raise the salary of every employee in the Sales department (DeptID D1) by 5000.

Write the statement and give the new salaries of E01 (52000) and E03 (61000).

Try it first, then show the solutionSolution
  1. UPDATE with a WHERE condition on the department.
  2. E01: 52000 + 5000 = 57000; E03: 61000 + 5000 = 66000.

Answer: UPDATE EMPLOYEE SET Salary = Salary + 5000 WHERE DeptID = 'D1'; gives 57000 and 66000.

Memory hook: No WHERE, and the whole company gets the raise.

A resignation

Suppose employee E06 leaves the company and her record must be removed.

Write the statement, and say what happens to the other rows.

Try it first, then show the solutionSolution
  1. DELETE FROM EMPLOYEE WHERE EmpID = 'E06';
  2. Only the row with EmpID E06 is removed; the other five rows are unchanged.

Answer: DELETE FROM EMPLOYEE WHERE EmpID = 'E06'; removes one row.

Memory hook: The primary key picks exactly one row.

Tricks to remember INSERT, UPDATE and DELETE Commands

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • Insert adds, Update changes, Delete removes

    The three verbs in order of the CRUD cycle.

    Use it when: Choosing the command.

  • WHERE is the seat belt

    Without WHERE, UPDATE and DELETE hit every row.

    Use it when: Missing condition errors.

  • Quotes for text and dates

    Numbers bare, text and dates in single quotes.

    Use it when: INSERT syntax.

  • NULL plus anything is NULL

    Arithmetic on NULL stays NULL.

    Use it when: UPDATE with NULL salary.

INSERT, UPDATE and DELETE Commands: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: Which command · 1 mark · MCQBoard level

Which SQL command is used to change existing values in a table?
(a) INSERT (b) ALTER (c) UPDATE (d) SELECT

Try it first, then show the solutionSolution
  1. ALTER changes the structure; UPDATE changes the values in rows.

Answer: (c) UPDATE

Example 2: Two insert statements · 2 marks · Short answerBoard level

Write statements to (i) insert the row (D5, Admin, Pune) into DEPT(DeptID, DName, Location); (ii) insert an employee with EmpID E08, Name Tara Nair, DeptID D2 into EMPLOYEE leaving the other columns empty.

Try it first, then show the solutionSolution
  1. (i) INSERT INTO DEPT VALUES ('D5', 'Admin', 'Pune'); (1 mark)
  2. (ii) INSERT INTO EMPLOYEE (EmpID, Name, DeptID) VALUES ('E08', 'Tara Nair', 'D2'); the unmentioned columns become NULL. (1 mark)

Answer: See the two statements above.

Example 3: UPDATE with a condition · 3 marks · Short answerHarder board level

Write a statement to increase the salary of the employees of department D1 by 5000, and show the Name and Salary of the D1 employees afterwards.

Try it first, then show the solutionSolution
  1. UPDATE EMPLOYEE SET Salary = Salary + 5000 WHERE DeptID = 'D1'; (2 marks)
  2. Asha Rao 57000 and Meena Iyer 66000. (1 mark)

Answer: Asha Rao 57000; Meena Iyer 66000

Example 4: DELETE and the missing WHERE · 3 marks · Short answerHarder board level

(i) Write a statement to delete the employees who work in Mumbai and list the EmpIDs left. (ii) What happens if WHERE is omitted?

Try it first, then show the solutionSolution
  1. (i) DELETE FROM EMPLOYEE WHERE City = 'Mumbai'; removes E02 and E06; the remaining rows are E01, E03, E04, E05. (2 marks)
  2. (ii) Without WHERE all rows are deleted; the empty table with its structure remains. (1 mark)

Answer: (i) E01, E03, E04, E05 remain (ii) all rows deleted, table remains

Example 5: Case: a sequence of changes · 4 marks · Case-basedHOTS / competency

Suppose the EMPLOYEE table has its six original rows (salaries 52000, 38000, 61000, 45000, NULL, 45000). These statements run in order:

INSERT INTO EMPLOYEE VALUES ('E07', 'Neha Jain', 'D4', 47000, 'Pune', '2024-01-08');
UPDATE EMPLOYEE SET Salary = Salary + 2000 WHERE Salary < 45000;
DELETE FROM EMPLOYEE WHERE DOJ < '2018-01-01';

(i) Which employees are updated? (1 mark)
(ii) Which employee is deleted? (1 mark)
(iii) How many rows remain? (1 mark)
(iv) What would SELECT SUM(Salary) FROM EMPLOYEE give? (1 mark)

Try it first, then show the solutionSolution
  1. (i) Only E02 (38000 becomes 40000); E05 has NULL, which does not satisfy the condition.
  2. (ii) E03 (DOJ 2017-01-20, before 2018-01-01).
  3. (iii) 6 + 1 - 1 = 6 rows (E01, E02, E04, E05, E06, E07).
  4. (iv) 52000 + 40000 + 45000 + 45000 + 47000 = 229000; the NULL is ignored by SUM.

Answer: (i) E02 (ii) E03 (iii) 6 (iv) 229000

Where students lose marks in INSERT, UPDATE and DELETE Commands

The slips examiners see most often, and what to write instead.

  • Mistake: UPDATE or DELETE without WHERE

    Every row is changed or removed.

    Wrong working

    DELETE FROM EMPLOYEE; (to remove one employee)

    Right working

    DELETE FROM EMPLOYEE WHERE EmpID = 'E06';

    Do this: Ask: which rows? and write the condition.

    Usually costs: 1 mark

  • Mistake: Text without quotes

    Text and dates must be in single quotes.

    Wrong working

    INSERT INTO DEPT VALUES (D5, Admin, Pune);

    Right working

    INSERT INTO DEPT VALUES ('D5', 'Admin', 'Pune');

    Do this: Quote every text and date value.

    Usually costs: 1 mark

  • Mistake: Expecting NULL to be updated by arithmetic

    NULL + 2000 is NULL; the condition Salary < 45000 does not match NULL either.

    Wrong working

    E05 salary becomes 2000

    Right working

    E05 salary stays NULL

    Do this: Treat NULL as unknown in every calculation.

    Usually costs: 1 mark

Exam tips

  • After INSERT, UPDATE or DELETE questions, recompute the table from the final rows.
  • Use WHERE with the primary key to target exactly one row.
  • Quote text and dates; leave numbers bare.
  • State the effect on the number of rows when asked about cardinality.
  • Remember that UPDATE and DELETE are DML, while DROP TABLE is DDL.

Practice questions on INSERT, UPDATE and DELETE Commands

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    Which statement removes all the rows of a table but keeps the table?
    (a) DROP TABLE T; (b) DELETE FROM T; (c) ALTER TABLE T DROP; (d) REMOVE T;

    Hint

    Rows, not structure.

    Answer

    (b) DELETE FROM T;

  2. Q2 · 1 mark · Very short answerBoard level

    What is the effect of UPDATE EMPLOYEE SET City = 'Pune'; (no WHERE clause)?

    Hint

    Which rows are changed?

    Answer

    Every row of the table gets City = Pune.

  3. Q3 · 2 marks · Short answerHarder board level

    Write a statement to set the salary of employee E05 to 36000 and DeptID to D4.

    Hint

    Two columns in one SET.

    Answer

    UPDATE EMPLOYEE SET Salary = 36000, DeptID = 'D4' WHERE EmpID = 'E05';

  4. Q4 · 1 mark · Assertion-reasonHarder board level

    Assertion (A): INSERT INTO EMPLOYEE VALUES ('E08', 'Tara') fails for the six-column EMPLOYEE table.
    Reason (R): When no column list is given, a value must be supplied for every column.
    (a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.

    Hint

    Count the values given.

    Answer

    (a) Both are true and R explains A: two values for six columns is rejected.

  5. Q5 · 3 marks · Short answerHOTS / competency

    The original EMPLOYEE table receives, in order: UPDATE EMPLOYEE SET Salary = 50000 WHERE Salary IS NULL; DELETE FROM EMPLOYEE WHERE Salary = 45000; INSERT of E07 (Neha Jain, D4, 47000, Pune, 2024-01-08). Find COUNT(*), SUM(Salary), MAX(Salary) and MIN(Salary) of the final table.

    Hint

    Work out the surviving rows first.

    Answer

    After the UPDATE E05 has 50000. The DELETE removes E04 and E06. Rows: E01 52000, E02 38000, E03 61000, E05 50000, E07 47000. COUNT(*) = 5; SUM = 248000; MAX = 61000; MIN = 38000.

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.Which command adds a new row?Show answer

    INSERT INTO.

  2. 2.Which command changes existing values?Show answer

    UPDATE ... SET.

  3. 3.Which command removes rows?Show answer

    DELETE FROM.

  4. 4.What happens to omitted columns in an INSERT with a column list?Show answer

    They become NULL (or their default).

  5. 5.What does DELETE FROM T; do?Show answer

    Deletes all rows, keeps the table.

  6. 6.How must a date be written?Show answer

    In quotes as YYYY-MM-DD.

INSERT, UPDATE and DELETE Commands: frequently asked questions

What is the difference between DELETE and DROP?

DELETE removes rows from a table and keeps the structure (DML). DROP TABLE removes the table with its structure and all rows (DDL).

What happens if I forget the WHERE clause in UPDATE?

The change is applied to every row of the table.

Can INSERT be given values for only some columns?

Yes, with a column list. The remaining columns become NULL or their default value, unless a constraint such as NOT NULL forbids it.

Does UPDATE change the degree or cardinality?

No. UPDATE changes only values in existing rows, so neither the number of rows nor the number of columns changes.