How to drop SQL Server Schema

USE MyData;
GO

— Drop failed because schema is not empty
DROP SCHEMA Sch;
GO
Msg 3729, Level 16, State 1, Line 1
Cannot drop schema ‘Sch’ because it is being referenced
   by object ‘DF__sch_test__creat__4316F928’.

— Move one table out
ALTER SCHEMA dbo TRANSFER Sch.test;
GO

— Delete one table
DROP TABLE Sch.test;
GO

— Dropped ok
DROP SCHEMA Sch;
GO

Command(s) completed successfully.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s