First google search yielded me this answer. So I thought of updating this with newer version of attach, detach.
Create database dbname
On
(
Filename= 'path where you copied files',
Filename ='path where you copied log'
)
For attach;
Further,if your database is cleanly shutdown(there are no active transactions while database was shutdown) and you dont have log file,you can use below method,SQL server will create a new transaction log file..
Create database dbname
On
(
Filename= 'path where you copied files'
)
For attach;
if you don't specify transaction log file,SQL will try to look in the default path and will try to use it irrespective of whether database was cleanly shutdown or not..
Here is what MSDN has to say about this..
If a read-write database has a single log file and you do not specify a new location for the log file, the attach operation looks in the old location for the file. If it is found, the old log file is used, regardless of whether the database was shut down cleanly. However, if the old log file is not found and if the database was shut down cleanly and has no active log chain, the attach operation attempts to build a new log file for the database.
There are some restrictions with this approach and some side affects too..
1.attach-and-detach operations both disable cross-database ownership chaining for the database
2.Database trustworthy is set to off
3.Detaching a read-only database loses information about the differential bases of differential backups.
Most importantly..you can't attach a database with recent versions to an earlier version
References:
https://msdn.microsoft.com/en-in/library/ms190794.aspx