Re: How to attach db with missing log file?
From: Jasper Smith (jasper_smith9_at_hotmail.com)
Date: 03/20/04
- Next message: Joel: "Using Backup to create new db"
- Previous message: Jim: "Upgrade Errors - 6.5 to 2000"
- In reply to: Merlin: "Re: How to attach db with missing log file?"
- Next in thread: Merlin: "Re: How to attach db with missing log file?"
- Messages sorted by: [ date ] [ thread ]
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! > > > > > >. > >
- Next message: Joel: "Using Backup to create new db"
- Previous message: Jim: "Upgrade Errors - 6.5 to 2000"
- In reply to: Merlin: "Re: How to attach db with missing log file?"
- Next in thread: Merlin: "Re: How to attach db with missing log file?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|