It is absolutely not a requirement in this very specific case, but it is a requirement in many other scenarios. If you're creating a database called
Sales, and you arelady have a database called
Sales, you'll need to change your database context before you:
- Restore with replace; or,
- Drop the current database and then:
- Create from scratch; or,
- Create for attach.
There are plenty of other scenarios outside of database creation that also require either (a) not being in the context of the current database, or (b) being in the context of
master specifically (or at least not a specific database), and many of these things you may be doing during or around creating databases:
- Setting a database to a different state, like
- Preventing errors when a script has a
USE command but that user database may be offline or otherwise inaccessible
- Granting server-level permissions like
- Granting server-level role membership
- Marking a module as a system object (
sp_MS_marksystemobject) or as a startup procedure
- Certain types of certificate, server audit, and Availability Group operations
Probably a slew of other things.
USE master; isn't always necessary, but sometimes it is, and it doesn't hurt to always execute server-level commands from that database.