The SQL UPDATE Statement
Credit:   Image by Freepik
The SQL UPDATE
statement is used to modify existing records in a database table. It allows you to change the values of one or more columns based on specified conditions.
Using the UPDATE Statement
Here's the basic syntax of the UPDATE
statement:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Let's consider a sample database table called "Customers" with the following structure:
CustomerID | CustomerName | City | PostalCode | Country | Address |
---|---|---|---|---|---|
1 | John Doe | New York | 10001 | USA | 123 Main St |
Customer Database Table
CustomerID | CustomerName | City | PostalCode | Country | Address |
---|---|---|---|---|---|
1 | John Doe | New York | 10001 | USA | 123 Main St |
2 | Jane Smith | Los Angeles | 90001 | USA | 456 Elm St |
This is a demo database table called "Customers" that showcases customer details. Customize the content and structure of the table to match your specific requirements.
Now, let's see an example of using the UPDATE
statement:
Example: Updating Customer Information
UPDATE Customers SET City = 'Los Angeles', PostalCode = '90001' WHERE CustomerID = 1;
This query updates the "City" and "PostalCode" columns for a customer with the "CustomerID" value of 1. The customer's information is modified to reflect the new values of 'Los Angeles' for the city and '90001' for the postal code.
Conclusion
The SQL UPDATE
statement is a powerful tool for modifying existing records in a database table. By specifying the columns and their new values, you can update the data according to your requirements. Use the UPDATE
statement to make changes to your database tables effectively.
0 Comments