Re: How to attach db with missing log file?

From: Jasper Smith (jasper_smith9_at_hotmail.com)
Date: 03/20/04


Date: Sat, 20 Mar 2004 00:11:43 -0000

Not supported etc and make sure you have a copy of the mdf before starting
this. Also replace the relavent database,drive letters and filenames with
your particulars as this answer was for a specific case.

1) Make sure you have a copy of PowerDVD301_2_Data.MDF

2) Create a new database called fake (default file locations)

3) Stop SQL Service

4) Delete the fake_Data.MDF and copy PowerDVD301_2_Data.MDF
    to where fake_Data.MDF used to be and rename the file to fake_Data.MDF

5) Start SQL Service

6) Database fake will appear as suspect in EM

7) Open Query Analyser and in master database run the following :

sp_configure 'allow updates',1
go
reconfigure with override
go
update sysdatabases set
   status=-32768 where dbid=DB_ID('fake')
go
sp_configure 'allow updates',0
go
reconfigure with override
go

This will put the database in emergency recovery mode

8) Stop SQL Service

9) Delete the fake_Log.LDF file

10) Restart SQL Service

11) In QA run the following (with correct path for log)

dbcc rebuild_log('fake','h:\fake_log.ldf')
go
dbcc checkdb('fake') -- to check for errors
go

12) Now we need to rename the files, run the following (make sure
there are no connections to it) in Query Analyser
(At this stage you can actually access the database so you could use
DTS or bcp to move the data to another database .)

use master
go

sp_helpdb 'fake'
go

/* Make a note of the names of the files , you will need them
in the next bit of the script to replace datafilename and
logfilename - it might be that they have the right names */

sp_renamedb 'fake','PowerDVD301'
go

alter database PowerDVD301
MODIFY FILE(NAME='datafilename', NEWNAME = 'PowerDVD301_Data')
go

alter database PowerDVD301
MODIFY FILE(NAME='logfilename', NEWNAME = 'PowerDVD301_Log')
go

dbcc checkdb('PowerDVD301')
go

sp_dboption 'PowerDVD301','dbo use only','false'
go

use PowerDVD301
go

sp_updatestats
go

13) You should now have a working database. However the log file
       will be small so it will be worth increasing its size
       Unfortunately your files will be called fake_Data.MDF and
       fake_Log.LDF but you can get round this by detaching the
       database properly and then renaming the files and reattaching
       it

14) Run the following in QA

sp_detach_db PowerDVD301

--now rename the files then reattach

sp_attach_db 'PowerDVD301','h:\dvd.mdf','h:\DVD.ldf'

-- 
HTH
Jasper Smith (SQL Server MVP)
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"Merlin" <anonymous@discussions.microsoft.com> wrote in message
news:d87301c40e01$69052ec0$a601280a@phx.gbl...
> Thank you for your help. sp_attach_single_file_db is not
> allowing me to get past the missing log file, either. is
> there any other way?
>
>
>
> >-----Original Message-----
> >Hi
> >
> >You may be able to use sp_attach_single_file_db, although
> this would not be
> >guaranteed.
> >
> >John
> >
> >"Merlin" <anonymous@discussions.microsoft.com> wrote in
> message
> >news:bc7201c40dfc$f3419e20$a001280a@phx.gbl...
> >> I just detached a larg db with multiple empty log files.
> >> While moving the db to another server, a drive array
> onthe
> >> first one went bad, taking one of my log files with it.
> >> How can I re-attach the db and have it ignore that its
> >> missing a log file?
> >> Thank you in advance!
> >
> >
> >.
> >


Relevant Pages

  • Re: Shrinking MDF and LDF Files
    ... I don't have any problem with my database log file growing in size ... actions are then required to complete the shrinking of the transaction log: ... Microsoft Online Community Support ...
    (microsoft.public.access.adp.sqlserver)
  • RE: Shrink File?
    ... As my understanding of you problem, you have a database with a data file ... in the log file. ... You can truncate only nonactive portion of the transaction log. ...
    (microsoft.public.sqlserver.setup)
  • Re: PerfMon recording to SQL 2005
    ... seconds or even every ne second) from a busy server to a database on ... On the Perfmon counter Log Files tab, SQL Database has been set, End File ... Configuring the log file, choose the tested DSN as the System DSN ... The user account I created in SQL is an owner of the ...
    (microsoft.public.sqlserver.server)
  • Re: sp_attach_single_file_db
    ... Being that Rob has access to the database and can still ... Stop sql server and rename the existing MDF to a new one and copy the ... Now execute the undocumented DBCC to create a log file ...
    (microsoft.public.sqlserver.server)
  • Transaction log problems
    ... just before you backup the ... database change the recovery model to ... Simple, shrink the log file then change it back to Full, ... >transaction log and it is causing us some problems. ...
    (microsoft.public.sqlserver.server)

Loading