Obviously you can detach the whole dbs and reattach using sp_attach and sp_detach. Is there an online way to do this, have had a quick google but can't see anything.
If you want to move the log file without having to take a database offline there is a way I used before. I just hope I remember it correctly:
Add a new log file in the new location with something like:
ALTER DATABASE foo ADD LOG FILE (NAME=NewLog, FILENAME='YourNewPhysicalPath', SIZE=100MB, other options ...);
Empty the old log file with:
USE foo; DBCC SHRINKFILE(OldLog, EMPTYFILE);
Take log backup with BACKUP LOG foo...
Remove the old log file with:
ALTER DATABASE foo REMOVE FILE OldLog;
If the last one says you can not remove because the file is not empty, try executing 2 and 3 again and then 4.
EDIT: Well, it turns out that I have not remebered it correctly... IT WILL NOT WORK this way and as gbn pointed out you can not "empty" the logfile via SHRINKFILE (but it was not my goal anyway - I just wanted to mark the file as "not for use" so it is not reused and can be dropped later). I think a similar technique is still possible for any additional logfiles you have apart from the first one but I will post about it when I get a chance to research that.
The best way, which will require some down time, is to use ALTER DATABASE ... SET OFFLINE. There are several good reasons for this.
- The database owner is not changed. This can have implications with respect to implied permissions and cross database ownership chaining.
- Configurations like FILESTREAM (in 2008) or database specific configuration (like cross database ownership chaining) are not lost.
- The database is not re-attached using the wrong name. Fat fingering still happens.
Sorry, there is no "safe" on-line method.
You have to take the database off-line or detach it.
You can not "empty" a log file like you can a data file.