How to modify data in a table in SQL Server?
To modify data in a table, you can use the UPDATE statement in SQL Server.
The basic syntax of an UPDATE statement is as follows:
UPDATE 表名
SET 列名1 = 新值1, 列名2 = 新值2, ...
WHERE 条件;
In this case, the table name refers to the name of the table to be modified, the column name is the name of the column to be altered, the new value is the value to be updated to, and the condition is the requirement that must be met.
For example, suppose there is a table called employees, with columns id, name, and age. If we want to change the age of an employee with id 1 to 30, we can use the following SQL statement:
UPDATE employees
SET age = 30
WHERE id = 1;
This will change the age of the employee with id 1 in the employees table to 30.
It’s important to note that the UPDATE statement will modify all rows that meet the condition. If the WHERE clause is not specified, it will modify all rows in the table. Therefore, when using the UPDATE statement, be cautious and ensure the conditions are accurate.