- Open the command prompt on the server.
- From the command prompt, connect to an instance of SQL Server by using the following sqlcmd command:
sqlcmd -S Server\Instance
Where Server is the name of the computer and Instance is the name of the instance.
- When connected, type the following commands:
USE [master] GO CREATE DATABASE [database_name] ON ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\<database name>.mdf' ), ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\<database name>.ldf' ) FOR ATTACH ; GO
Where database_name is the name of the database you want to attach, FileName is the path and file name of the database file and the log file, and FOR ATTACH specifies that the database is created by attaching an existing set of operating system files.
- To verify that the database has been attached, type the following two commands:
select name from sys.databases go
- The sqlcmd tool displays the names of all databases attached to this instance of SQL Server Express. In the list, you should see the database name you provided in step 3.
(from here)
Notice: Don’t forget to run command prompt with administrative permissions.
Also, if you are interesting Microsoft has moved sample databases for SQL Server from MSDN to CodePlex, so now they available here. There is an MSI installation that by default will install Sample Database files into your SQL Server Data directory.
Here is some additional information about sample databases installation on Journey to SQL Authority with Pinal Dave