Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of modifying Table content by sql

Shulou Source: shulou.com Published: 2022-06-01 03:25:42 10月04日 Update

Editor to share with you the method of sql to modify the contents of the table, I hope you will learn a lot after reading this article, let's discuss it together!

There are three ways to modify the contents of tables in sql: using SSMS database management tools to modify contents, using T-SQL scripts to modify contents, and multi-table association to modify table contents, etc.

Modify data using SSMS database management tools

You can modify any one or more of them.

1: open the database, select the data table, right-click-"Edit all rows (if not configured, click Edit the first 200 rows).

2. Edit the data that needs to be modified-"after editing, right-click on the blank space -" Select to execute SQL to edit successfully.

Use T-SQL scripts to modify data

Modify single-column or multi-column 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 ('1million and 2'); update test1 set age='22' where id between' 3' and '4update test1 set age='23' where id > =' 5' and id = '5toy update test1 set age='23' where test1.id in (select top (2) id from test1 order by id desc)

Example result:

Multi-table association modifies 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=' Li Hua', test1.sex=' female 'from test1 as an as b where a.classid=b.id Test2

Example result:

After reading this article, I believe you have a certain understanding of the method of sql to modify the contents of the table, want to know more about it, welcome to follow the industry information channel, thank you for reading!

Tags: Data content examples methods databases results grammars tools conditions administrative tools articles scripts associations management selection success one line multiple entries done datasheet Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Shulou Tech Info Xiaomi Shulou Information