11

Just noticed this and was having a hard time coming up with a technical reason for it.

Tables can be dropped using three part names, but views are restricted to two part names.

What is the reasoning behind this?

9

The documentation is skimpy on this, merely stating (and providing a syntax diagram) that only current database is relevant.

Removes one or more views from the current database.

DROP VIEW [ IF EXISTS ] [ schema_name . ] view_name [ ...,n ] [ ; ]  

Someone fluent in the debugger could determine if this is because of a code path that is only hit when dropping certain types of objects, or you could ask someone at Microsoft. Regardless of the reason, and whether or not you actually know the reason, you still need the same workarounds... you can do

USE your_database;
GO
DROP VIEW dbo.viewname;

Or:

EXEC your_database.sys.sp_executesql N'DROP VIEW dbo.viewname;';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.