Oct 8, 2015

How can I Update top 10 records in SQL Server

Hello guys suppose we have to update top 10 records in 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