Where does SQL Server LocalDB create its files, and what are those files?
Posted: (EET/GMT+2)
When you create or attach an SQL Server LocalDB instance, SQL Server places its files in your user profile by default.
The default path is:
C:\Users\\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB
Inside that folder you'll find (among others):
- Files "master.mdf" and "mastlog.ldf", these are the system database files for the LocalDB instance itself
- Temporary and error log files
- Folders for user databases you attach manually.
When you create a new database under LocalDB without a specific path, it stores the .MDF and .LDF files under your "AppData\Local" by default
To see where your database files are, query:
SELECT name, physical_name FROM sys.master_files;
If you want to keep them elsewhere, specify the file path explicitly:
CREATE DATABASE MyAppDb ON (NAME = MyAppDb_Data, FILENAME = 'C:\Data\MyAppDb.mdf') LOG ON (NAME = MyAppDb_Log, FILENAME = 'C:\Data\MyAppDb.ldf');
These tips should get you going to the right direction. Remember to backup your LocalDB databases as well!