Top Keyword With Delete Statement In SQL

In this article i will explain how to use the top keyword in a delete query to delete only the top few records.
  • 1050

Introduction

Basically, most of us know about top, we can use it in a select query to get the top element from the query. But TOP can also be used with Insert, Delete and Update commands for the table as well. We will see how we can use TOP with Delete statement.

Syntax

Delete top (N) from <Table Name> where <Cond>

where N represents number of top rows to be deleted.

Example

We have table named Employee.

CreateTable-in-sql.jpg


To delete top 2 employees from Employee Table having Salary greater than 20,000.

TopKeyword-with-Delete-in-SQL.jpg


OUTPUT:

Delete-Top-Rows-in-sql.jpg


© 2013 dotNetheaven. All rights reserved.