Home >Database >Mysql Tutorial >How to modify table contents in sql
SQL method to modify table contents: You can modify it by executing the [update table name set column name 1=value, column name 2=value where condition;] command. Use this command to modify a row, a single column or multiple columns of data in a single table.
There are three ways to modify the content of a table in sql: using SSMS database management tools to modify the content, using T-SQL scripts to modify the content and multiple tables Association changes the content in the table, etc.
(Recommended tutorial: mysql video tutorial)
Use SSMS database management tool to modify data
Modify any one or more All are OK
1: Open the database, select the data table, right-click -> Edit all rows (if not configured, click to edit the first 200 rows).
#2. Edit the data that needs to be modified - "After the editing is completed, right-click on the blank space -" Select Execute SQL to edit successfully.
Use T-SQL script to modify data
Modify one row, single column or multiple columns of data in a single table
Syntax: update table name set column name 1 = value, column name 2 = value where condition;
Example 1:
update test1 set age='21' where id='1';
Example result:
Modify multiple rows, one column or multiple columns of data in a single table
Syntax: update top(quantity) table name set column name 1=value, column name 2=value 2 where Condition;
Example:
update test1 set age='23' where id in ('1','2'); update test1 set age='22' where id between '3' and '4'; update test1 set age='23' where id>='5' and id <='6'; update top(2) test1 set age='23' where id>='5'; update test1 set age='23' where test1.id in (select top(2) id from test1 order by id desc);
Example result:
##Multiple table association Modify the data in the table
Syntax: update table 1 set table 1. column 1 = value, table 1. column 2 = value from table 1 as a, table 2 as b where a. column name = b. Column name;Example:update test1 set test1.name='李华',test1.sex='女' from test1 as a,test2 as b where a.classid=b.id;Example result: Summary: Modification Data table data, flexible combination and modification of data columns, data sources, and query conditions are the key.
The above is the detailed content of How to modify table contents in sql. For more information, please follow other related articles on the PHP Chinese website!