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 |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-08-21 : 10:34:22
|
Sy writes "Hello, I have a SQL2K MDF that I cannot figure out how to reattach because :-1.) sp_detach_db was NOT used to cleanly dismount.2.) The LDF has been deleted and is unavailable.So my question is - How do I reattach an MDF when it was NOT detached firstly and the corresponding LDF is missing.I have looked everywhere for a full day and cannot find the answer to this seemingly straightforward procedure.Thanking you in advance, Sy" |
|
KnooKie
Aged Yak Warrior
623 Posts |
Posted - 2002-08-21 : 11:00:47
|
Perhaps you could recreate the DB as it was created originally. Then swap the newly created file with your oddly detached one.An ldf would've been created anyway.Even if you attach an mdf file on its own the ldf will create itself automatically at 1MB i believePaul |
|
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2002-08-21 : 11:09:26
|
You could try sp_attach_single_file_db.Look up the details in the Books OnlineMichael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
|
|
jasper_smith
SQL Server MVP & SQLTeam MVY
846 Posts |
Posted - 2002-08-21 : 12:35:32
|
If sp_attach_single_file_db fails as it sometimes does you can try the following technique (you need to change the database name and filenames as these were for a specific recovery)1) Make sure you have a copy of PowerDVD301_2_Data.MDF2) Create a new database called fake (default file locations)3) Stop SQL Service4) 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.MDF5) Start SQL Service6) Database fake will appear as suspect in EM7) Open Query Analyser and in master database run the following :sp_configure 'allow updates',1 go reconfigure with overridegoupdate sysdatabases set status=-32768 where dbid=DB_ID('fake')gosp_configure 'allow updates',0 go reconfigure with overridegoThis will put the database in emergency recovery mode8) Stop SQL Service9) Delete the fake_Log.LDF file10) Restart SQL Service11) In QA run the following (with correct path for log)dbcc rebuild_log('fake','h:\fake_log.ldf')godbcc checkdb('fake') -- to check for errorsgo12) 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 useDTS or bcp to move the data to another database .)use mastergosp_helpdb 'fake'go/* Make a note of the names of the files , you will need themin the next bit of the script to replace datafilename andlogfilename - it might be that they have the right names */sp_renamedb 'fake','PowerDVD301'goalter database PowerDVD301 MODIFY FILE(NAME='datafilename', NEWNAME = 'PowerDVD301_Data') goalter database PowerDVD301 MODIFY FILE(NAME='logfilename', NEWNAME = 'PowerDVD301_Log') godbcc checkdb('PowerDVD301')gosp_dboption 'PowerDVD301','dbo use only','false' gouse PowerDVD301gosp_updatestatsgo13) 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 QAsp_detach_db PowerDVD301--now rename the files then reattachsp_attach_db 'PowerDVD301','h:\dvd.mdf','h:\DVD.ldf'HTHJasper Smith |
|
|
|
|
|
|
|