In the SQL Server, use the Select statement to update the tableSQL Server can use the
statement to insert the results of thestatement into the table. This article discusses whether the
Different from sentences, SQL Server does not supportINSERT...SELECT
statement can be used to perform a similar update operation.SELECT
SELECT
Can SQL Server use the Select update table?grammar. However, you can use the combination of and statement to achieve similar functions.
Use join and set to update Create a statement to match the line to be updated.
INSERT...SELECT
UPDATE...SELECT
To use the data update table in the statement, please follow the following steps to operate:JOIN
SET
In the clause, specify the corresponding value of the column to be updated and the corresponding value of the statement.
Use the clause filtering line to ensure that only the expected lines affect the expected lines.
SELECT
For example, consider the following inquiries:
value is updated, and the- In this example,
JOIN
- The statement uses the
data modification ofSET
andSELECT
columns in the- in the matching
Make sure that only the line withWHERE
line.clause will be updated to
equal to 'cool'.<code class="language-sql">UPDATE Table_A SET Table_A.col1 = Table_B.col1, Table_A.col2 = Table_B.col2 FROM Some_Table AS Table_A INNER JOIN Other_Table AS Table_B ON Table_A.id = Table_B.id WHERE Table_A.col3 = 'cool';</code>Copy after login
The above is the detailed content of Can SQL Server Update Tables Using a SELECT Statement?. For more information, please follow other related articles on the PHP Chinese website!