I'm brand new to SQL and I'm practicing some queries with a DB. I've now just detached the database using Tasks > Detach
Question 1: When I detach a file, I'm guessing it's saved to an MDF file? Where would I locate this file?
Question 2: When I create a new DB, where do the related files get saved? I'm assuming an MDF and an LDF set of files are created.
If it helps, here's my version info
Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64) Mar 29 2009 10:11:52 Copyright (c) 1988-2008 Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)
Thanks!
The detached files can be found in the system location. You will find the MDF file and the log file associated with this main database. These files can be moved to any other location as well.
Use SQL Server Management StudioIn Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance. To see a list of all databases on the instance, expand Databases.
The detached files are not deleted and remain in the file system. The files can be reattached by using CREATE DATABASE ... FOR ATTACH or FOR ATTACH_REBUILD_LOG option. The files can also be moved to another server and attached to an instance with the same or newer version.
Ok so if you have already detached the database, and then realized that you are clueless where it is, you can do this trick.
Expand server, then on Databases
click Right Mouse then choose Attach...
Click Add...
Then in the new window that opens will be a path to the directory where your detached database is (if you haven't navigated from default location earlier)
Also, the default location for MSSql databases is:
C:\Program Files\Microsoft SQL Server\[YourSQLVersionGoesHere]\MSSQL\DATA
Hope this saves you some time.
You can always look at the database properties in your Object Explorer in SQL Server Management Studio before detaching - the file(s) will not be moved or anything when detaching....
In the Properties
dialog box, go to the Files
section and to your right, the relevant info can be found:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With