SQL Update

The UPDATE in SQL is used to modify existing records in a table. It allows you to change one or more values in one or more rows of a table.

SQL Update Syntax

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;


SQL Update Example

SQL Update Updating a Single Record Example

This query updates the contact_number to ‘555-9999’ for the patient with patient_id = 2 in the Patients table.

UPDATE Patients
SET contact_number = '555-9999'
WHERE patient_id = 2;




SQL Update Multiple Records Example

This query updates the status to ‘Rescheduled’ for all records in the Appointments table where the appointment_date is ‘2024-07-18’.

UPDATE Appointments
SET status = 'Rescheduled'
WHERE appointment_date = '2024-07-18';




SQL Update Multiple Columns Example

This query updates the contact_number to ‘555-1234’ and the dob (date of birth) to ‘1991-01-15’ for the patient with patient_id = 5 in the Patients table.

UPDATE Patients
SET contact_number = '555-1234', dob = '1991-01-15'
WHERE patient_id = 5;




SQL Update Visual Diagram




SQL Update Labs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top