Monday, February 22, 2010

Shrinking the log file via detach/attach

Always take a full backup before a detach.

Detach the database, delete/rename the log file, attach the database - this will create a minimum size log file.

Note that the log file must be deleted/renamed otherwise it will be re-used even though it is not mentioned in the attach.

Enterprise managerRight click on the database, All tasks, Detach database, OK.
Delete/rename the disk log file.
Right click on databases, All tasks, Attach database, Select the .mdf file, OK, Yes (to the create new log message).

t-sql

sp_detach_db [dbname]
Delete/rename the disk log file.
sp_attach_single_file_db [dbname], [filename]
where [filename] is the name of the physical data file (.mdf).

No comments:

Post a Comment