Managing SQL Server Express databases

If you need to copy, move, or delete a SQL Server Express database, you must first detach the database from the server. Do not detach a database currently in use.

To determine whether a database is in use, do any of the following:

  • Verify that the date included in the file name has passed.
  • Check whether a database with a higher number exists for the current date.
  • Enter the following lines at the command prompt, to list as SQL Server Express databases that currently have open connections:
    OSQL -S computer_name\MSFW -E

Detach a database by typing the following at a command prompt:

OSQL -S computer_name\MSFW -E
sp_detach_db database_name

Where database_name is the name of the .mdf and .ldf files, without their extensions.