Wednesday, January 7, 2009

if you delete your transaction log



If you delete the transactionlog by mistake try this script

This script should fix a databases where the transaction log has been deleted or croupted. You will have do do some of this manually as explained it will take a while depending on the databases size.
/*
Stop SQL service, rename mydb.mdf to mydbBad.mdf.
started SQL service, created fake mydb db (with log etc)
Stopped SQL service
Deleted mydb.mdf
Renamed mydbBad.MDF to mydb.MDF
Started SQL service.
Ran following script:
*/
ALTER DATABASE mydb SET EMERGENCY
sp_dboption 'mydb', 'single user', 'true'
DBCC CHECKDB ('mydb', REPAIR_ALLOW_DATA_LOSS)
sp_dboption 'mydb', 'single user', 'false'

No comments:

Post a Comment