Renaming a Database
A topic that you’ll need sooner or later is how to rename a database. You’ll get a request to build a database, and it’ll be documented fairly well. You’ll be coding along, then you get a ping through IM.
-> Hey, you know that database you just created for me?
<- Yeah. I’ve already built the database, the tables, and most of the views. What’s up?
-> Yeah, I misspelled the name in the documentation, can you change that for me?
…Let’s break here. You’re probably a little upset they didn’t review the documentation before sending over the work order, right? Well, luckily this isn’t too tough a problem to solve.
To change the name of a database, Transact-SQL provides sp_renamedb. The syntax to actually change the name would be:
EXEC sp_renamedb 'ExistingName', 'NewName'
The ExistingName is the name of the database that you want to rename, and the NewName is the name you want the database to have after renaming it.
Here is an example of renaming a database:
EXEC sp_renamedb 'sorak', 'Zorack'
So now, you can continue that conversation from before…
<-No problem. What would you like the new database name be?
Hopefully, that will save you a little effort when you need it. If you have any questions, send them in…I’m here to help!