Why does the following SQL query throw an error when I've first selected the master database before dropping the database in question?
Please see error and code below:
Msg 3702, Level 16, State 4, Line 5
Cannot drop database "XyzCompany" because it is currently in use.Msg 1801, Level 16, State 3, Line 7
Database 'XyzCompany' already exists. Choose a different database name.
Code:
USE master;
GO
DROP DATABASE IF EXISTS XyzCompany;
CREATE DATABASE XyzCompany;
GO
USE XyzCompany;
GO