See sp_renamedb and sp_rename in SQL Server books online
1. Change the Database Name
Sp_renamedb
Change the database name.
Syntax
Sp_renamedb [ @ Dbname = ] ' Old_name ' ,
[ @ Newname = ] ' New_name '
Parameters
[ @ Dbname = ] ' Old_name '
Is the current name of the database. Old_name is of the sysname type and has no default value.
[@ Newname =] 'New_name'
Is the new name of the database. New_name must follow the identifier rules. New_name is of the sysname type and has no default value.
ReturnCodeValue
0(Successful) or non-zero number (failed)
Permission
Only members of SysAdmin and dbcreator fixed server roles can execute sp_renamedb.
Example
In the following example, change the database accounting to financial.
ExecSp_renamedb'Accounting','Financial'
Or
The logical and physical file names of the original database are inconsistent.
In the Enterprise Manager of SQL Server, it seems that you cannot directly change the database name. If you want to change the name, it is most convenient to run in the query Analyzer:
Alter database original database name
Modify name = new database name
In SQL Server, the physical file name can be changed during database restoration, or the database can be separated, and the MDF file name can be changed and appended directly. However, changing the logical file name does not seem so intuitive.
Run in the query Analyzer:
Alter database name
Modify file (name = original logical file name, newname = new logical file name)
In this way, you can change the logical file name. Because SQL Server has data files and log files, you must change the logical file names of both data files and log files, write two statements similar to the preceding statement.
Ii. Change the table name or column name
Sp_rename [ @ Objname = ] ' Object_name ' ,
[ @ Newname = ] ' New_name '
[ , [@ Objtype = ] ' Object_type ' ]
//////////////////////////////////////// /////
A. rename a table
In the following example, the customers table is renamed as custs.
exec sp_rename ' MERs ' , ' custs '
B. Rename the column
In the following example, rename the contact title column in the customers table to the title column.
ExecSp_rename'MERs. [contact title]','Title','Column'