How can I Update top 10 records in SQL Server


Hello, guys suppose we have to update the top 10 records in the table, the following query may help you.
CREATE TABLE #TMP
(
ID INT IDENTITY(1,1),
NAME VARCHAR(100),
SALARY DECIMAL(16,2)
)

INSERT INTO #TMP
SELECT 'N1',20000
UNION ALL
SELECT 'N2',15000
UNION ALL
SELECT 'N3',20000
UNION ALL
SELECT 'N4',30000
UNION ALL
SELECT 'N5',10000
UNION ALL
SELECT 'N6',25000
UNION ALL
SELECT 'N7',10000
UNION ALL
SELECT 'N8',50000
UNION ALL
SELECT 'N9',20000
UNION ALL
SELECT 'N10',20000
UNION ALL
SELECT 'N11',30000
UNION ALL
SELECT 'N12',40000
UNION ALL
SELECT 'N13',50000

SELECT * FROM #TMP


UPDATE TOP (10) #TMP SET SALARY=10000




SELECT * FROM #TMP

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

NUnit : Introduction

There are several unit test tools in the market, but one of them is NUnit, the most popular tool for doing unit testing. So in this tutorial...