Before
write query to use top keyword or clause with update and delete statements we need
to design table UserInformation in
database like as shown below
Column Name
|
Data Type
|
Allow Nulls
|
UserId
|
Int
(set Identity=true)
|
No
|
UserName
|
varchar(50)
|
Yes
|
Location
|
Varchar(50)
|
Yes
|
Once
table created enter some dummy data like as shown below
![]() |
Check
below methods to use Top keyword or clause with update and delete statements
Top keyword with Update Statement
Syntax
to use top keyword with update statement
UPDATE TOP(N) Table1 SET Column1='somevalue'
|
Example
UPDATE TOP(2) UserInformation
SET UserName='test2'
|
Once
we run above query our table UserInformation
will contain data like as shown below
Output
![]() |
Top keyword with delete statement
Syntax
to use top keyword with delete statement
DELETE TOP(N) FROM Table1
|
Example
DELETE TOP(2) FROm UserInformation
|
Once
we run above query our table UserInformation
will contain data like as shown below

No comments:
Post a Comment