T-sql语句修改SQL Server数据库逻辑名、数据库名、物理名的方法

栏目: 数据库 · SQL Server · 发布时间: 7年前

内容简介:这篇文章主要介绍了T-sql语句修改SQL Server数据库逻辑名、数据库名、物理名的方法,结合实例形式分析了T-SQL语句操作数据库的基本技巧,非常简单易懂,需要的朋友可以参考下

本文实例讲述了T-sql语句修改 SQL Server 数据库逻辑名、数据库名、物理名的方法。分享给大家供大家参考,具体如下:

更改MSSQL数据库物理文件名 Sql 语句的写法

注意:要在活动监视器里面确保没有进程连接你要改名的数据库!!!!!!!!!!!!!!!!!!!!

Sql语句如下

USE master
--改逻辑名
ALTER DATABASE YQBlog MODIFY FILE(NAME='YQBlogAA',NEWNAME='YQBlog')
-- GO
ALTER DATABASE YQBlog MODIFY FILE(NAME='YQBlogAA_log',NEWNAME='YQBlog_log')
-- GO
--改数据库名
EXEC sys.sp_renamedb @dbname = 'YQBlogAA', -- sysname
  @newname = 'YQBlog'
  GO
--分离数据库
EXEC sp_detach_db YQBlog
GO
--打开xp_cmdshell功能
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
---- --改物理名(注意:路径中不要出现中文)
EXEC xp_cmdshell 'ren C:\Users\Administrator\Desktop\YQBlogAA.mdf YQBlog.mdf'
---- --改物理名
EXEC xp_cmdshell 'ren C:\Users\Administrator\Desktop\YQBlogAA_log.ldf YQBlog_log.ldf'
--GO
---- --重新附加
EXEC sp_attach_db @dbname = N'YQBlog',
  @filename1 = N'C:\Users\Administrator\Desktop\YQBlog.mdf',
  @filename2 = N'C:\Users\Administrator\Desktop\YQBlog_log.ldf'

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Nature of Code

The Nature of Code

Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95

How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具