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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 create database

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 files

Please 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 Larsson
Helsingborg, Sweden
Go to Top of Page

putane.sanjay
Yak Posting Veteran

77 Posts

Posted - 2007-01-23 : 02:24:45
what using sp_attach _db
Go to Top of Page

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_db
quote:
sp_attach_db
Attaches a database to a server.

Syntax
sp_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 Values
0 (success) or 1 (failure)

Result Sets
None

Remarks
sp_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.

Permissions
Only members of the sysadmin and dbcreator fixed server roles can execute this procedure.

Examples
This 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 Larsson
Helsingborg, Sweden
Go to Top of Page

putane.sanjay
Yak Posting Veteran

77 Posts

Posted - 2007-01-23 : 03:07:19
Thank you for your kind help database is attached successfully.
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -