How do i load sql database file into ssms

David Cutler 40 Reputation points
2025-10-04T19:35:55.9066667+00:00

i have a sql database file from another computer. how do i load it into ssms on a new computer?

SQL Server Migration Assistant
SQL Server Migration Assistant
A Microsoft tool designed to automate database migration to SQL Server from Access, DB2, MySQL, Oracle, and SAP ASE.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Marcin Policht 63,730 Reputation points MVP Volunteer Moderator
    2025-10-04T21:04:12.0266667+00:00

    Step 1: Verify what files you have

    You should have one or both of these:

    • YourDatabase.mdf → the primary data file (required)
    • YourDatabase_log.ldf → the transaction log file (optional; SQL Server can recreate it if missing)

    Step 2: Copy files to the SQL Server machine

    Move the .mdf (and .ldf if available) to a safe folder on the same machine where SQL Server is installed, such as:

    C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA
    

    Step 3: Attach the database using SSMS

    1. Open SQL Server Management Studio (SSMS).
    2. Connect to your SQL Server instance.
    3. In Object Explorer, right-click Databases → Attach...
    4. Click Add..., browse to the .mdf file.
      • SSMS will automatically detect the .ldf file if it’s in the same folder.
    5. Click OK.

    The database will appear under Databases in SSMS.

    You can do the same via a query window:

    CREATE DATABASE YourDatabase
    ON (FILENAME = 'C:\Data\YourDatabase.mdf'),
       (FILENAME = 'C:\Data\YourDatabase_log.ldf')
    FOR ATTACH;
    

    If you don’t have the log file, you can tell SQL Server to rebuild it:

    CREATE DATABASE YourDatabase
    ON (FILENAME = 'C:\Data\YourDatabase.mdf')
    FOR ATTACH_REBUILD_LOG;
    

    If you only have a .bak file instead of .mdf, the process is different — you'd restore it instead of attaching.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    2 people found this answer helpful.

Answer accepted by question author
  1. Akhil Gajavelly 645 Reputation points Microsoft External Staff Moderator
    2025-10-06T12:35:25.73+00:00

    Hi @David Cutler,

    If the solutions provided by the @Marcin Policht & @Erland Sommarskog are sufficient and applicable to your situation, then a big thank you to them for their helpful guidance. Please go ahead and try the steps suggested by Super Users. Whether you're attaching the .mdf file directly or considering a backup/restore approach, both methods are valid depending on what files you have and how your setup is configured.

    Thanks,
    Akhil.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.