Home >Database >Mysql Tutorial >How to modify table contents in sql

How to modify table contents in sql

清浅
清浅Original
2019-05-14 09:50:2047063browse

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.

How to modify table contents in sql

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).

How to modify table contents in sql

#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.

How to modify table contents in sql

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:

How to modify table contents in sql

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=&#39;23&#39; where id>=&#39;5&#39; and id <=&#39;6&#39;;
update top(2) test1 set age=&#39;23&#39; where id>=&#39;5&#39;;
update test1 set age=&#39;23&#39; where test1.id in (select top(2) id from test1 order by id desc);

Example result:

How to modify table contents in sql

How to modify table contents in sql

##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=&#39;李华&#39;,test1.sex=&#39;女&#39; from test1 as a,test2 as b where a.classid=b.id;

Example result:

How to modify table contents in sql

How to modify table contents in sql

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does block mean?Next article:What does block mean?

Related articles

See more