Skip to content

Latest commit

 

History

History
88 lines (67 loc) · 3.18 KB

drop-schema-transact-sql.md

File metadata and controls

88 lines (67 loc) · 3.18 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
DROP SCHEMA (Transact-SQL)
DROP SCHEMA (Transact-SQL)
WilliamDAssafMSFT
wiassaf
05/11/2017
sql
t-sql
reference
DROP SCHEMA
DROP_SCHEMA_TSQL
deleting schemas
schemas [SQL Server], removing
DROP SCHEMA statement
dropping schemas
removing schemas
TSQL
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current||=fabric

DROP SCHEMA (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw]

Removes a schema from the database.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

-- Syntax for SQL Server and Azure SQL Database  
  
DROP SCHEMA  [ IF EXISTS ] schema_name  
-- Syntax for Azure Synapse Analytics and Parallel Data Warehouse  
  
DROP SCHEMA schema_name  

Arguments

IF EXISTS
Applies to: [!INCLUDEssNoVersion] ( [!INCLUDEsssql16-md] through current version).

Conditionally drops the schema only if it already exists.

schema_name
Is the name by which the schema is known within the database.

Remarks

The schema that is being dropped must not contain any objects. If the schema contains objects, the DROP statement fails.

Information about schemas is visible in the sys.schemas catalog view.

Caution [!INCLUDEssCautionUserSchema]

Permissions

Requires CONTROL permission on the schema or ALTER ANY SCHEMA permission on the database.

Examples

The following example starts with a single CREATE SCHEMA statement. The statement creates the schema Sprockets that is owned by Krishna and a table Sprockets.NineProngs, and then grants SELECT permission to Anibal and denies SELECT permission to Hung-Fu.

CREATE SCHEMA Sprockets AUTHORIZATION Krishna   
    CREATE TABLE NineProngs (source INT, cost INT, partnumber INT)  
    GRANT SELECT TO Anibal   
    DENY SELECT TO [Hung-Fu];  
GO  

The following statements drop the schema. Note that you must first drop the table that is contained by the schema.

DROP TABLE Sprockets.NineProngs;  
DROP SCHEMA Sprockets;  
GO  

See Also

CREATE SCHEMA (Transact-SQL)
ALTER SCHEMA (Transact-SQL)
DROP SCHEMA (Transact-SQL)
EVENTDATA (Transact-SQL)