Moving Databases

After reading on how to harden MSSQL 2005 installation, I realized the current directory structure doesn't lend itself for easy management of hardening the SQL installation, therefore, I am on a quest of moving the logical files in the database to a directory structure that makes it easier to lock down.

To move a single database it is somewhat easy.

ALTER DATABASE [name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [name] SET OFFLINE

[move physical files]

[ don't forget each file {data/tLog/fulltext} ]
ALTER DATABASE [name] MODIFY FILE (NAME = 'logicalname' , FILENAME =  'LogicalFilename'

ALTER DATABASE [name] SET ONLINE
ALTER DATABASE [name] SET MULTI_USER

Moving all the databases wasn't that difficult either, it was just remembering to exec() the sql.  Also, using a script all databases had to be setup the same.  I had one database that had more than one data file - 2 for data, 2 for indexes.  I had to do that one manually.

There is another way also, use sql to PRINT the needed sql commands, and then use those printed commands to execute in the order you need.






Comments

Popular posts from this blog

ColdFusion in an Enterprise Environment - Part 1 - Understanding how to use SubVersion (SVN)

coldfusion builder 2 extension not displaying browse button on type=projectdir

Being Thread Safe in Coldbox/Coldfusion