Home >Database >Mysql Tutorial >How to Update the Top N Records in a SQL Server Table?
Query to Update Top Records in SQL Server
This article addresses the challenge of updating a specific number of records at the top of a table in SQL Server. Consider a scenario where you have a table named T1 with fields F1 and F2, and you need to update the F1 field in the top 100 records.
To accomplish this update based on TOP 100 in SQL Server, you can utilize the following query:
update top (100) T1 set F1 = 1
It's important to note that parentheses are necessary in UPDATE statements for this syntax to work effectively. By specifying TOP (100), you instruct the query to update the first 100 records in the table.
This query effectively updates the F1 field with a value of 1 for the top 100 records in table T1.
The above is the detailed content of How to Update the Top N Records in a SQL Server Table?. For more information, please follow other related articles on the PHP Chinese website!