- SQL Tutorial
- SQL Tutorial
- SQL Display Data
- SQL Update Records
- SQL Delete Record
- SQL Alter Table
- SQL Join Tables
- SQL Auto Increment
- SQL Drop Table/Database
- Computer Programming
- Learn Python
- Python Keywords
- Python Built-in Functions
- Python Examples
- Learn C++
- C++ Examples
- Learn C
- C Examples
- Learn Java
- Java Examples
- Learn C#
- Learn Objective-C
- Web Development
- Learn HTML
- Learn CSS
- Learn JavaScript
- JavaScript Examples
- Learn PHP
Update Existing Records in SQL
In this post, you will learn how to update the record of a table. When I say "update the record," I mean "update the row." Since each row contains one or more columns, indirectly, it is about to update the column values of any specific rows.
To achieve this task, SQL provides the UPDATE statement. Here is the general form of the SQL UPDATE statement that can be used to update the records of a table.
UPDATE tableName SET column1 = newValue1, column2 = newValue2, ..., columnN = newValueN WHERE condition;
The WHERE clause is required to be included while updating the record of a table, until and unless you want to update all the records.
Now let me create a SQL query that will update the record of a table named "customer."
UPDATE customer SET email='newxyzemail@xyz.com' WHERE id = 3;
After executing the above SQL query, the column "email" will be updated with "newxyzemail@xyz.com." Since I used the WHERE clause to only update the record whose id value is equal to 3, therefore, only that particular row will be updated.
If you need to update only one record in a table, then always specify the value of the primary key. Otherwise, if you want to update multiple records, then you can choose any other condition, like to update all records whose city is "Austin," then use the following SQL query:
UPDATE customer SET email='design@company.com' WHERE city='Austin';
« Previous Topic Next Topic »