Wednesday, May 10, 2006

SQL Server: How to rename a database

I use Enterprise Manager for most operations in SQL Server. I feel really guilty about it, because I was strictly command-line with Oracle. Anyway, I recently needed to rename a SQL Server database. I fired up Enterprise Manager and did not find it as an option. Not F2, not rename, nothing.

Here are the commands to rename a SQL Server database:


EXEC sp_dboption 'old_name', 'Single User', 'TRUE'
EXEC sp_renamedb 'old_name', 'new_name'
EXEC sp_dboption 'new_name', 'Single User', 'FALSE'

No comments:

Post a Comment

I moderate comments blog posts over 14 days old. This keeps a lot of spam away. I generally am all right about moderating. Thanks for understanding.