Skip to content

Latest commit

 

History

History
96 lines (74 loc) · 3.2 KB

File metadata and controls

96 lines (74 loc) · 3.2 KB
title DROP SEQUENCE (Transact-SQL) | Microsoft Docs
ms.custom
SQL2016_New_Updated
ms.date 2015-10-28
ms.prod sql-non-specified
ms.reviewer
ms.suite
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
DROP SEQUENCE
DROP_SEQUENCE_TSQL
dev_langs
TSQL
helpviewer_keywords
DROP SEQUENCE statement
sequence number object, dropping
ms.assetid c25772d3-61af-4aa7-b58b-a6f67a793e3d
caps.latest.revision 20
author BYHAM
ms.author rickbyh
manager jhubbard

DROP SEQUENCE (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2012-asdb-xxxx-xxx_md]

Removes a sequence object from the current database.

Topic link icon Transact-SQL Syntax Conventions

Syntax

  
DROP SEQUENCE [ IF EXISTS ] { [ database_name . [ schema_name ] . | schema_name. ]    sequence_name } [ ,...n ]  
 [ ; ]  

Arguments

IF EXISTS

Applies to: [!INCLUDEssNoVersion] ([!INCLUDEssSQL15] through current version).

Conditionally drops the sequence only if it already exists.

database_name
Is the name of the database in which the sequence object was created.

schema_name
Is the name of the schema to which the sequence object belongs.

sequence_name
Is the name of the sequence to be dropped. Type is sysname.

Remarks

After generating a number, a sequence object has no continuing relationship to the number it generated, so the sequence object can be dropped, even though the number generated is still in use.

A sequence object can be dropped while it is referenced by a stored procedure, or trigger, because it is not schema bound. A sequence object cannot be dropped if it is referenced as a default value in a table. The error message will list the object referencing the sequence.

To list all sequence objects in the database, execute the following statement.

SELECT sch.name + '.' + seq.name AS [Sequence schema and name]   
    FROM sys.sequences AS seq  
    JOIN sys.schemas AS sch  
        ON seq.schema_id = sch.schema_id ;  
GO  

Security

Permissions

Requires ALTER or CONTROL permission on the schema.

Audit

To audit DROP SEQUENCE, monitor the SCHEMA_OBJECT_CHANGE_GROUP.

Examples

The following example removes a sequence object named CountBy1 from the current database.

DROP SEQUENCE CountBy1 ;  
GO  

See Also

ALTER SEQUENCE (Transact-SQL)
CREATE SEQUENCE (Transact-SQL)
NEXT VALUE FOR (Transact-SQL)
Sequence Numbers