Updating Top Records in SQL Server
In SQL Server, modifying the desired number of records at the beginning of a table or a view is often necessary. Suppose you want to update just the top portion of a dataset, such as the top 100 records, without affecting the rest. This can be achieved using the TOP clause in an UPDATE statement.
Example
Consider a table named "T1" with two columns: "F1" and "F2". It contains 200 records, and you want to modify the "F1" column in the top 100 records. To do this, use the following syntax:
UPDATE TOP (100) T1 SET F1 = 1
Explanation
Note
The parentheses around TOP (100) are essential for proper syntax in the UPDATE statement.
The above is the detailed content of How to Update Only the Top N Records in SQL Server?. For more information, please follow other related articles on the PHP Chinese website!