Hi Friends,
I want to know How to change Database name in SQL Server ?
Change Database Name
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted May 9, 2012, 6:07 PM EDT
Supported in SQL Server 2000 and 2005
exec sp_renamedb "test", "test1"
Supported in SQL Server 2005 and later version
ALTER Database "test1" Modify Name="test"
Thanks
Jignesh TrivediRank #16 · 50.3K reputationPosted May 9, 2012, 8:13 PM EDT
to rename database you have three option.
Option 1:Use the following T-SQL(command to make the database name change0.
EXEC sp_renamedb 'oldName', 'newName'
OR
ALTER DATABASE oldName MODIFY NAME = newName
This new command that should be used for SQL Serer 2005 and beyond.
Option 2
If you are using SQL Server Management Studio, right click on the database name and select the option "rename".
Option 3
Use the detach and attach feature of SQL Server to detach the database first and when you reattach the database you give the database a different name. This can be done by using the GUI or you can do this by using the following commands:
EXEC sp_detach_db 'oldDBName', 'true'
EXEC sp_attach_db @dbname = N'newDBName', @filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf', @filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'
hope this help.
MuthuMari MRank #5,738 · 288 reputationPosted May 9, 2012, 9:33 PM EDT
use this line,
sp_renamedb 'oldDBName', 'newDBName'
pls refer this url
http://www.mssqltips.com/sqlservertip/1122/how-to-rename-a-sql-server-database/
thanks
If this post is useful then mark it as "Accepted Answer"