08.23.06

Rename SQL Server database

Posted in Microsoft Sql server at 9:34 am by Tijs Vandormael

If you ever find yourself in a situation where you need to rename a SQL Server database you could use the following 3 statements to do the job:

-- Make sure that you are the only user accessing the db
EXEC sp_dboption 'old name', 'Single User', 'TRUE'
-- Rename the db
EXEC sp_renamedb 'old name', 'new name'
-- Allow other users to login again
EXEC sp_dboption 'new name', 'Single User', 'FALSE'

Leave a Comment