Introduction:
Here I will explain how to use top clause or keyword with update and delete statements in SQL Server.
Here I will explain how to use top clause or keyword with update and delete statements in SQL Server.
Description:
In previous post I explained use top clause with insert statement in
SQL
Server and many more articles relating to SQL
Server. Now I will explain how to use top clause with update and
delete statements in SQL Server.
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
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.