Reputation: 2292
When I call CREATE DATABASE [Hello World]
SQL Server creates my database, but also automatically adds tables to the database. These tables are from Entity Framework's migrations.
Where would I look to stop it from creating these tables on every new database?
Upvotes: 0
Views: 105
Reputation: 9134
You should take a look a the model database. According to MIcrosoft, it is used as a template when new databases are created. This has been true for a very long time.
ADDED
I know that the MS article mentions this, but model is also used when creating tempdb.
Took me a while to find this article that describes System Databases -- probably worth the time to read it.
ADDED
Don't change model (or any other system database) unless you know what you are doing. But I don't recall any tables in model, there is plenty of system views stored procs, etc. though. If it is just application data, you can get rid of it -- unless the application depends on application tables being "magically created" when a new database is created. You can change model like any other database, subject to permissions (and the additional restricted documented in the MS article on model)
ADDED
BTW, as a safety tip. Even if you have to log on frequently with full database privilege. Do not allow your default database to be one of the system databases. Change your usual admin login to point to your application database, or a dummy database to reduce the likelihood of accidentally changing a system database. You don't want to be the guy that accidentally screws up master.
Upvotes: 5