|
1 | | ---- |
2 | | -description: "DROP SCHEMA (Transact-SQL)" |
3 | | -title: "DROP SCHEMA (Transact-SQL) | Microsoft Docs" |
4 | | -ms.custom: "" |
5 | | -ms.date: "05/11/2017" |
6 | | -ms.prod: sql |
7 | | -ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" |
8 | | -ms.reviewer: "" |
9 | | -ms.technology: t-sql |
10 | | -ms.topic: "language-reference" |
11 | | -f1_keywords: |
12 | | - - "DROP SCHEMA" |
13 | | - - "DROP_SCHEMA_TSQL" |
14 | | -dev_langs: |
15 | | - - "TSQL" |
16 | | -helpviewer_keywords: |
17 | | - - "deleting schemas" |
18 | | - - "schemas [SQL Server], removing" |
19 | | - - "DROP SCHEMA statement" |
20 | | - - "dropping schemas" |
21 | | - - "removing schemas" |
22 | | -ms.assetid: 874aa29e-c8ad-41e4-a672-900fdc58f1f6 |
23 | | -author: markingmyname |
24 | | -ms.author: maghan |
25 | | -monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current" |
26 | | ---- |
27 | | -# DROP SCHEMA (Transact-SQL) |
28 | | -[!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)] |
29 | | - |
30 | | - Removes a schema from the database. |
31 | | - |
32 | | -  [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md) |
33 | | - |
34 | | -## Syntax |
35 | | - |
36 | | -```syntaxsql |
37 | | --- Syntax for SQL Server and Azure SQL Database |
38 | | - |
39 | | -DROP SCHEMA [ IF EXISTS ] schema_name |
40 | | -``` |
41 | | - |
42 | | -``` |
43 | | --- Syntax for Azure Synapse Analytics and Parallel Data Warehouse |
44 | | - |
45 | | -DROP SCHEMA schema_name |
46 | | -``` |
47 | | - |
48 | | -[!INCLUDE[sql-server-tsql-previous-offline-documentation](../../includes/sql-server-tsql-previous-offline-documentation.md)] |
49 | | - |
50 | | -## Arguments |
51 | | - *IF EXISTS* |
52 | | - **Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ( [!INCLUDE[ssSQL15](../../includes/sssql15-md.md)] through [current version](https://go.microsoft.com/fwlink/p/?LinkId=299658)). |
53 | | - |
54 | | - Conditionally drops the schema only if it already exists. |
55 | | - |
56 | | - *schema_name* |
57 | | - Is the name by which the schema is known within the database. |
58 | | - |
59 | | -## Remarks |
60 | | - The schema that is being dropped must not contain any objects. If the schema contains objects, the DROP statement fails. |
61 | | - |
62 | | - Information about schemas is visible in the [sys.schemas](../../relational-databases/system-catalog-views/schemas-catalog-views-sys-schemas.md) catalog view. |
63 | | - |
64 | | - **Caution** [!INCLUDE[ssCautionUserSchema](../../includes/sscautionuserschema-md.md)] |
65 | | - |
66 | | -## Permissions |
67 | | - Requires CONTROL permission on the schema or ALTER ANY SCHEMA permission on the database. |
68 | | - |
69 | | -## Examples |
70 | | - 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`. |
71 | | - |
72 | | -```sql |
73 | | -CREATE SCHEMA Sprockets AUTHORIZATION Krishna |
74 | | - CREATE TABLE NineProngs (source INT, cost INT, partnumber INT) |
75 | | - GRANT SELECT TO Anibal |
76 | | - DENY SELECT TO [Hung-Fu]; |
77 | | -GO |
78 | | -``` |
79 | | - |
80 | | - The following statements drop the schema. Note that you must first drop the table that is contained by the schema. |
81 | | - |
82 | | -```sql |
83 | | -DROP TABLE Sprockets.NineProngs; |
84 | | -DROP SCHEMA Sprockets; |
85 | | -GO |
86 | | -``` |
87 | | - |
88 | | - |
89 | | -## See Also |
90 | | - [CREATE SCHEMA (Transact-SQL)](../../t-sql/statements/create-schema-transact-sql.md) |
91 | | - [ALTER SCHEMA (Transact-SQL)](../../t-sql/statements/alter-schema-transact-sql.md) |
92 | | - [DROP SCHEMA (Transact-SQL)](../../t-sql/statements/drop-schema-transact-sql.md) |
93 | | - [EVENTDATA (Transact-SQL)](../../t-sql/functions/eventdata-transact-sql.md) |
| 1 | +--- |
| 2 | +description: "DROP SCHEMA (Transact-SQL)" |
| 3 | +title: "DROP SCHEMA (Transact-SQL) | Microsoft Docs" |
| 4 | +ms.custom: "" |
| 5 | +ms.date: "05/11/2017" |
| 6 | +ms.prod: sql |
| 7 | +ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" |
| 8 | +ms.reviewer: "" |
| 9 | +ms.technology: t-sql |
| 10 | +ms.topic: "language-reference" |
| 11 | +f1_keywords: |
| 12 | + - "DROP SCHEMA" |
| 13 | + - "DROP_SCHEMA_TSQL" |
| 14 | +dev_langs: |
| 15 | + - "TSQL" |
| 16 | +helpviewer_keywords: |
| 17 | + - "deleting schemas" |
| 18 | + - "schemas [SQL Server], removing" |
| 19 | + - "DROP SCHEMA statement" |
| 20 | + - "dropping schemas" |
| 21 | + - "removing schemas" |
| 22 | +ms.assetid: 874aa29e-c8ad-41e4-a672-900fdc58f1f6 |
| 23 | +author: markingmyname |
| 24 | +ms.author: maghan |
| 25 | +monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current" |
| 26 | +--- |
| 27 | +# DROP SCHEMA (Transact-SQL) |
| 28 | +[!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)] |
| 29 | + |
| 30 | + Removes a schema from the database. |
| 31 | + |
| 32 | +  [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md) |
| 33 | + |
| 34 | +## Syntax |
| 35 | + |
| 36 | +```syntaxsql |
| 37 | +-- Syntax for SQL Server and Azure SQL Database |
| 38 | + |
| 39 | +DROP SCHEMA [ IF EXISTS ] schema_name |
| 40 | +``` |
| 41 | + |
| 42 | + |
| 43 | +```syntaxsql |
| 44 | +-- Syntax for Azure Synapse Analytics and Parallel Data Warehouse |
| 45 | + |
| 46 | +DROP SCHEMA schema_name |
| 47 | +``` |
| 48 | + |
| 49 | +[!INCLUDE[sql-server-tsql-previous-offline-documentation](../../includes/sql-server-tsql-previous-offline-documentation.md)] |
| 50 | + |
| 51 | +## Arguments |
| 52 | + *IF EXISTS* |
| 53 | + **Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ( [!INCLUDE[ssSQL15](../../includes/sssql15-md.md)] through [current version](https://go.microsoft.com/fwlink/p/?LinkId=299658)). |
| 54 | + |
| 55 | + Conditionally drops the schema only if it already exists. |
| 56 | + |
| 57 | + *schema_name* |
| 58 | + Is the name by which the schema is known within the database. |
| 59 | + |
| 60 | +## Remarks |
| 61 | + The schema that is being dropped must not contain any objects. If the schema contains objects, the DROP statement fails. |
| 62 | + |
| 63 | + Information about schemas is visible in the [sys.schemas](../../relational-databases/system-catalog-views/schemas-catalog-views-sys-schemas.md) catalog view. |
| 64 | + |
| 65 | + **Caution** [!INCLUDE[ssCautionUserSchema](../../includes/sscautionuserschema-md.md)] |
| 66 | + |
| 67 | +## Permissions |
| 68 | + Requires CONTROL permission on the schema or ALTER ANY SCHEMA permission on the database. |
| 69 | + |
| 70 | +## Examples |
| 71 | + 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`. |
| 72 | + |
| 73 | +```sql |
| 74 | +CREATE SCHEMA Sprockets AUTHORIZATION Krishna |
| 75 | + CREATE TABLE NineProngs (source INT, cost INT, partnumber INT) |
| 76 | + GRANT SELECT TO Anibal |
| 77 | + DENY SELECT TO [Hung-Fu]; |
| 78 | +GO |
| 79 | +``` |
| 80 | + |
| 81 | + The following statements drop the schema. Note that you must first drop the table that is contained by the schema. |
| 82 | + |
| 83 | +```sql |
| 84 | +DROP TABLE Sprockets.NineProngs; |
| 85 | +DROP SCHEMA Sprockets; |
| 86 | +GO |
| 87 | +``` |
| 88 | + |
| 89 | + |
| 90 | +## See Also |
| 91 | + [CREATE SCHEMA (Transact-SQL)](../../t-sql/statements/create-schema-transact-sql.md) |
| 92 | + [ALTER SCHEMA (Transact-SQL)](../../t-sql/statements/alter-schema-transact-sql.md) |
| 93 | + [DROP SCHEMA (Transact-SQL)](../../t-sql/statements/drop-schema-transact-sql.md) |
| 94 | + [EVENTDATA (Transact-SQL)](../../t-sql/functions/eventdata-transact-sql.md) |
0 commit comments