Professional Documents
Culture Documents
How To Rename A SQL Server Database
How To Rename A SQL Server Database
If you are using SQL Server 2000 you can use the T-SQL command
below to make the database name change. This still works for SQL
2005, 2008, 2008R2, 2012, 2014, 2016, 2017 and 2019, but Microsoft
says it will be phased out at some time.
Then attach the database using the files from the first command
above:
EXEC sp_attach_db
@dbname = N'Test2',
@filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL14.SQL2017\MSSQL\DATA\
test.mdf',
@filename2 = N'C:\Program Files\Microsoft SQL Server\MSSQL14.SQL2017\MSSQL\DATA\
test_log.ldf'
Right click on database "Test" and select Tasks > Detach... and
the following will open. Click OK to detach the database.
Then click the Add button and select the MDF file for the database
you want to reattach.
I will open another query window and USE database Test2, this way
there is another connection to the Test2 database.