Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginner's SQL: How do I find a detached database?

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!

like image 599
Ray Avatar asked Jul 20 '11 22:07

Ray


People also ask

Where does a detached database go?

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.

How do I find an existing SQL database?

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.

How do I reattach a detached database?

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.


2 Answers

Ok so if you have already detached the database, and then realized that you are clueless where it is, you can do this trick.

  1. Expand server, then on Databases click Right Mouse then choose Attach...

  2. Click Add...

  3. 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

enter image description here

enter image description here

Hope this saves you some time.

like image 169
Matas Vaitkevicius Avatar answered Oct 21 '22 20:10

Matas Vaitkevicius


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....

enter image description here

In the Properties dialog box, go to the Files section and to your right, the relevant info can be found:

enter image description here

like image 31
marc_s Avatar answered Oct 21 '22 21:10

marc_s