The SQL UPDATE Statement is used to modify the existing records in a table. This statement is a part of Data Manipulation Language (DML), as it only modifies the data present in a table without affecting the table's structure.
Basic Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
-UPDATE: Specifies that you're updating existing records in the table.
-table_name: The name of the table you want to update.
-SET: Specifies the columns you want to update along with their new values.
column1 = value1, column2 = value2, ...: This part specifies the columns you want to update and the new values you want to set for them.
-WHERE: This clause is optional but very important. It allows you to specify which records should be updated based on a condition. If you omit the WHERE clause, all records in the table will be updated with the new values.
Example:
Let's say you have a table called students with columns name, age, and grade, and you want to update the age of a student named "John" to 25. Your SQL query would look like this:
UPDATE students
SET age = 25
WHERE name = 'John';
This query will update the age column to 25 for all records where the name column equals 'John'.
Remember to be cautious when using the UPDATE statement, as it modifies existing data in your database, and incorrect usage could result in unintended consequences. Always double-check your conditions and values before executing an update query.