Wednesday, March 28, 2012

Moving Transaction logs

I am running a SQL Server and want to move the transaction logs of all the
databases to another disk. I detached one of the databases, moved the
transaction log file to another disk and then tried to re-attach the database
-- specifying the new log file. But I got an error.
How should I move the transaction logs ?
Thanks,
Craig
Detach and attach is generally considered to be the best way to move database files. You need to be
more specific about what you did and the error you got if you want help. Here's a script showing
create, detach, copy file, delete original file and attach:
CREATE DATABASE test_db
ON PRIMARY
( NAME = a,
FILENAME = N'c:\a.mdf',
SIZE = 1MB,
MAXSIZE = 200MB,
FILEGROWTH = 10%)
LOG ON
( NAME = l,
FILENAME = N'c:\l.ldf',
SIZE = 512KB,
MAXSIZE = 200MB,
FILEGROWTH = 10%)
GO
EXEC sp_detach_db test_db
EXEC master..xp_cmdshell 'copy c:\l.ldf c:\temp\l.ldf'
EXEC master..xp_cmdshell 'del c:\l.ldf'
EXEC sp_attach_db 'test_db', 'c:\a.mdf', 'c:\temp\l.ldf'
EXEC test_db..sp_helpfile
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:3D7FC130-4CA5-4B54-AD04-491AF0F79CB1@.microsoft.com...
>I am running a SQL Server and want to move the transaction logs of all the
> databases to another disk. I detached one of the databases, moved the
> transaction log file to another disk and then tried to re-attach the database
> -- specifying the new log file. But I got an error.
> How should I move the transaction logs ?
> Thanks,
> Craig
|||That code you posted worked -- thanks for that.
- Craig

No comments:

Post a Comment