While you can certainly rename a SQL Server database in the SSMS GUI by right-clicking on the database name and selecting Rename, sometimes you might prefer (or need) to do it using Transact-SQL.
The most basic way to rename a database using T-SQL is like this:
-- Change to the master database USE master; -- Change the database name ALTER DATABASE Films Modify Name = Movies; GO
The only problem with this basic script is that it doesn’t change the name of the data files and log files. In most cases you’ll probably want to change the names of these files to match the new name. In that case you can take the following script and replace the database name with your own (as well as its file names and paths):
Continue reading