--系统表里存放各个数据库属性信息的表之一
SELECT name AS [Logical Name], physical_name AS [DB File Path],type_desc AS [File Type],
state_desc AS [State] FROM sys.master_files WHERE database_id = DB_ID(N'cardTest20160106')
--修改数据库名
--alter DATABASE cardTest20160106 modify name=cardTest201601
--将数据库修改为单用户模式
--ALTER DATABASE cardTest20160106 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
--GO
--修改数据库的逻辑文件名
--ALTER DATABASE cardTest20160106 MODIFY FILE (NAME=N'cardTest20160106', NEWNAME=N'cardTest201601')
--GO
--修改数据库日志的逻辑文件名
--ALTER DATABASE cardTest20160106 MODIFY FILE (NAME=N'cardTest_log', NEWNAME=N'cardTest201601_log')
--GO
--将数据库改为多用户模式
--ALTER DATABASE cardTest20160106 SET MULTI_USER
--GO
--将数据库改为文件存储路径
--alter database cardTest201601 modify file ( name = cardTest201601, filename = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\cardTest201601.mdf');
--alter database cardTest201601 modify file ( name = cardTest201601_log, filename = 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\cardTest201601_log.ldf');
--修改系统表里的数据库配置,但是目前不可用,sqlserver的安全验证已经这个表的直接修改屏蔽,所以暂时用上面的方法
--UPDATE sys.master_files SET physical_name='C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\cardTest201601.mdf' WHERE database_id IN (12) AND name='cardTest201601'
--UPDATE sys.master_files SET physical_name='C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\cardTest201601_log.ldf' WHERE database_id IN (12) AND name='cardTest201601_log'