Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

use top clause with update delete statements in SQL Server

Aug 7, 2012
Introduction:

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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.