Sonzaschool
Back

O-Level · Form 2 · Vocational · Electronics and Computer

Computer Programming

Implementing updating and deletion of data in a database

about 3 minutes to read

Discussions
Topics in this sectionLinking forms to databases for interactive web applications3 topics

Updating and deleting data are two fundamental operations that allow us to modify or remove existing records in a database. After learning how to insert and retrieve data, we now focus on how to change (update) or remove (delete) information when needed — for example, correcting a customer's phone number or removing an out-of-stock item from an inventory.

The UPDATE statement is used to modify existing records in a table. It changes the values of specified columns for rows that meet a certain condition.

Basic Syntax

UPDATE table_name
SET column1 = new_value1, column2 = new_value2
WHERE condition;
  • UPDATE table_name — specifies which table to modify
  • SET column = new_value — defines the column(s) to change and their new values
  • WHERE condition — identifies which row(s) to update; without this, ALL rows would be updated!

Worked Example

Consider a table called students at Mwenge Secondary School:

idnamephonestream
1Amina Rajabu0755123456Science
2Emmanuel John0655789012Arts
3Fatuma Hamisi0713234567Science

Amina changes her phone number. The UPDATE query:

UPDATE students
SET phone = '0689123456'
WHERE id = 1;

After this update, Amina's record now shows 0689123456.

If we want to change all Science stream students to "Science A":

UPDATE students
SET stream = 'Science A'
WHERE stream = 'Science';

How you'll be assessedProcess assessment · Outcome assessment · Knowledge assessment

Process assessment

  • Create HTML forms to update database records using UPDATE

Outcome assessment

Interactive forms that allow users to modify or delete database records (e.g.,

Knowledge assessment

Detailed knowledge of:

Method used: The student should explain how to

  • write UPDATE

Question

What is the correct SQL syntax to update a customer's phone number in a table named customers where the customer ID is 5?

Sign in to submit your answer and have it count toward your mastery.

Sign in to practice

Tutor

Stuck? Ask me anything about this topic.

Sign in to ask the Sonza AI Tutor about this question.

Sign in to ask

Discussions

No questions yet

Sign in to ask
Loading discussions…