Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
putane.sanjay
Yak Posting Veteran
77 Posts |
Posted - 2007-01-23 : 02:12:13
|
Hi I have mdf file and ldf file how to create a database using these filesPlease suggest me |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-23 : 02:14:48
|
Attach the mdf file.The mdf file IS the database.Peter LarssonHelsingborg, Sweden |
 |
|
putane.sanjay
Yak Posting Veteran
77 Posts |
Posted - 2007-01-23 : 02:24:45
|
what using sp_attach _db |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-23 : 02:35:14
|
Let's see what Books Online has to say see about sp_attach_dbquote: sp_attach_dbAttaches a database to a server.Syntaxsp_attach_db [ @dbname = ] 'dbname' , [ @filename1 = ] 'filename_n' [ ,...16 ] Arguments[@dbname =] 'dbname'Is the name of the database to be attached to the server. The name must be unique. dbname is sysname, with a default of NULL. [@filename1 =] 'filename_n'Is the physical name, including path, of a database file. filename_n is nvarchar(260), with a default of NULL. There can be up to 16 file names specified. The parameter names start at @filename1 and increment to @filename16. The file name list must include at least the primary file, which contains the system tables that point to other files in the database. The list must also include any files that were moved after the database was detached.Return Code Values0 (success) or 1 (failure)Result SetsNoneRemarkssp_attach_db should only be executed on databases that were previously detached from the database server using an explicit sp_detach_db operation. If more than 16 files must be specified, use CREATE DATABASE with the FOR ATTACH clause.If you attach a database to a server other than the server from which the database was detached, and the detached database was enabled for replication, you should run sp_removedbreplication to remove replication from the database.PermissionsOnly members of the sysadmin and dbcreator fixed server roles can execute this procedure.ExamplesThis example attaches two files from pubs to the current server.EXEC sp_attach_db @dbname = N'pubs', @filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf', @filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'
It seems that you are right!Peter LarssonHelsingborg, Sweden |
 |
|
putane.sanjay
Yak Posting Veteran
77 Posts |
Posted - 2007-01-23 : 03:07:19
|
Thank you for your kind help database is attached successfully. |
 |
|
swatib
Posting Yak Master
173 Posts |
Posted - 2007-01-24 : 00:22:04
|
Even if you have only MDF file not LDF file , it is fine. In the absence of the log file (.ldf), SQL Server creates a new log file.Njoy Life |
 |
|
madhuotp
Yak Posting Veteran
78 Posts |
Posted - 2007-01-24 : 01:00:58
|
quote: Originally posted by swatib Even if you have only MDF file not LDF file , it is fine. In the absence of the log file (.ldf), SQL Server creates a new log file.Njoy Life 
it is not always so... if the detached database had multiple log file then this way will not work.. you should be very careful before doing attach db without log file.Madhu |
 |
|
|
|
|
|
|