The DROP SCHEMA statement could be used to delete a schema from a database. SQL Server have some built-in schema, for example : dbo, guest, sys, and INFORMATION_SCHEMA which cannot be deleted.
Syntax :
DROP SCHEMA [IF EXISTS] schema_name;
Note : Delete all objects from the schema before dropping the schema. If the schema have any object in it, the output will be an error.
Example :
Let us create a new schema named geeksh (https://www.geeksforgeeks.org/create-schema-in-sql-server/);
CREATE SCHEMA geeksh; GO
Now create a table named geektab inside the geeksh schema :
CREATE TABLE geeksh.geektab (id INT PRIMARY KEY, date DATE NOT NULL, city varchar(200) NOT NULL);
Drop the schema geeksh :
DROP SCHEMA geeksh;
SQL Server will throw similar error as the schema is not empty.
Msg 3729, Level 16, State 1, Line 1 Cannot drop schema 'geeksh' because it is being referenced by object 'geektab'.
Let us drop the table geeksh.geektab :
DROP TABLE geeksh.geektab;
Again run the DROP SCHEMA again to drop the geeksh schema :
DROP SCHEMA IF EXISTS geeksh;
Now, the geeksh schema has been deleted from the database.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
Recommended Posts:
- Create, Alter and Drop schema in MS SQL Server
- Difference between Star Schema and Snowflake Schema
- Difference between Snowflake Schema and Fact Constellation Schema
- Difference between Star Schema and Fact Constellation Schema
- CREATE SCHEMA in SQL Server
- ALTER SCHEMA in SQL Server
- Drop login in SQL Server
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- SQL | DROP, TRUNCATE
- SQL | ALTER (ADD, DROP, MODIFY)
- Difference between DELETE and DROP in SQL
- Difference between DROP and TRUNCATE in SQL
- CREATE and DROP INDEX Statement in SQL
- Snowflake Schema in Data Warehouse Model
- Schema Integration in DBMS
- Strategies for Schema design in DBMS
- Star Schema in Data Warehouse modeling
- Difference between Schema and Database
- Difference between Schema and Instance in DBMS
- Relation Schema in DBMS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

