DROP SEQUENCE (Transact-SQL)DROP SEQUENCE (Transact-SQL)

适用对象:是SQL Server 是Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server yesAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

从当前数据库中删除序列对象。Removes a sequence object from the current database.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

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

参数Arguments

IF EXISTSIF EXISTS
适用范围SQL ServerSQL ServerSQL Server 2016 (13.x)SQL Server 2016 (13.x)当前版本)。Applies to: SQL ServerSQL Server ( SQL Server 2016 (13.x)SQL Server 2016 (13.x) through current version).

只有在序列已存在时才对其进行有条件地删除。Conditionally drops the sequence only if it already exists.

database_namedatabase_name
要在其中创建序列对象的数据库的名称。Is the name of the database in which the sequence object was created.

schema_nameschema_name
序列对象所属架构的名称。Is the name of the schema to which the sequence object belongs.

sequence_namesequence_name
要删除的序列的名称。Is the name of the sequence to be dropped. 类型为 sysname。Type is sysname.

RemarksRemarks

在生成编号后,序列对象与其生成的编号之间没有延续关系,因此可以删除序列对象,即使生成的编号仍在使用。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  

SecuritySecurity

权限Permissions

要求具有架构的 ALTER 或 CONTROL 权限。Requires ALTER or CONTROL permission on the schema.

审核Audit

若要审核 DROP SEQUENCE,请监视 SCHEMA_OBJECT_CHANGE_GROUPTo audit DROP SEQUENCE, monitor the SCHEMA_OBJECT_CHANGE_GROUP.

示例Examples

以下示例从当前数据库中删除一个名为 CountBy1 的序列对象。The following example removes a sequence object named CountBy1 from the current database.

DROP SEQUENCE CountBy1 ;  
GO  

另请参阅See Also

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