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?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
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;
EXEC your_database.sys.sp_executesql N'DROP VIEW dbo.viewname;';