Tip of the Day : SQL Server Tutorial - DELETE Statement 101

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - April 01, 2025

SQL Server Tutorial - DELETE Statement 101

The DELETE statement is a Data Manipulation Language (DML) statement that removes one or more rows from a table or view.

A simplified form of the DELETE statement syntax is as follows:

DELETE < table_or_view >
FROM < table_source >
WHERE < search_condition >

The < table_or_view > parameter names a table or view from which the rows are to be deleted. All rows in the < table_or_view > that meet the < search_condition > specified in the WHERE clause are deleted. If a WHERE clause is not specified, all the rows in the < table_or_view > are deleted.

The FROM clause specifies additional tables or views and join conditions that can be used by the predicates in the WHERE clause search condition to qualify the rows to be deleted from the < table_or_view >. Rows are not deleted from the tables named in the FROM clause but only from the table named in the < table_or_view >.

Here are a few examples of how to use the DELETE statement:

Using DELETE to Delete All Rows in a Table

DELETE FROM [dbo].[Transactions]

Using DELETE to Delete Certain Rows in a Table

DELETE FROM [dbo].[Account]
WHERE [IsExpired] = 1

Using DELETE to Delete Certain Number of Rows Only

DELETE TOP (1000)
FROM [dbo].[Transactions]
WHERE [TransactionDate] <= '2013/01/01'

Using DELETE to Delete Rows Based on Another Table

DELETE [dbo].[OrderDetails]
FROM [dbo].[OrderDetails] INNER JOIN [dbo].[OrderHeader]
                                  ON [dbo].[OrderDetails].[OrderID] = [dbo].[OrderHeader].[OrderID]
WHERE [dbo].[OrderHeader].[OrderNumber] = 'ABC123'

Using DELETE to Deleta Rows Based on Another Table Using Table Alias

DELETE [Det]
FROM [dbo].[OrderDetails] [Det] INNER JOIN [dbo].[OrderHeader] [Hdr]
                                        ON [Det].[OrderID] = [Hdr].[OrderID]
WHERE [Hdr].[OrderNumber] = 'ABC123'

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions