Friday, January 30, 2015

Moving a SQL User Database

To move a SQL user database, follow these steps:

1. Take db offline
ALTER DATABASE database_name SET OFFLINE;
GO

2. Use windows explorer to move the data and log files to the new location while the database is offline

3. Change the paths to the files
ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_path\os_file_name' );
GO

4. Bring db back online
ALTER DATABASE database_name SET ONLINE;
GO

5. Verify that the database is online
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'');

No comments:

Post a Comment

SQL 2022 TSQL snapshot backups!

  SQL 2022 now actually supports snapshot backups!  More specifically, T-SQL snapshot backups. Of course this is hardware-dependent. Here ...