zoukankan      html  css  js  c++  java
  • 数据库改名系列(数据库名,逻辑名,物理文件名)

    汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql

    某系统设计的不是很合理,库很多,图形化操作分离都得搞半天,各种改名也就更浪费时间了,于是引入了命令~(SQLServer现在已经在Linux里面跑了,咱们也得跟上时代)

    1.数据库名修改前

    alter database Test modify name=NewTest or exec sp_renamedb 'Test','NewTest'

    2.数据库名修改后

    3.物理文件名和逻辑名并没有变化

    4.逻辑名修改前后

    alter database NewTest modify file(name=N'Test', newname=N'NetTest')

    5.逻辑名发生改变物理文件名不变

    6.物理改名很多种(我这边的本质就是分离后修改,因为占用状态是没法修改的)

    其实并没有什么新的sql,都是组合版的

    exec xp_cmdshell 'rename E:SQLTest.mdf NewTest.mdf'

    效果:

    SQL:

    use master
    go
    --1.分离
    exec sp_detach_db NewTest
    go
    
    --2.改名(这一步可以换成手动改名字)
    exec sp_configure 'show advanced options',1 --显示高级选项
    reconfigure with override--重新配置
    	exec sp_configure 'xp_cmdshell',1 --1代表允许,0代表阻止
    	reconfigure with override
    		exec xp_cmdshell 'rename E:SQLTest.mdf NewTest.mdf'
    		go
    		exec xp_cmdshell 'rename E:SQLTest_log.ldf NewTest_log.ldf'
    		go
    	exec sp_configure 'xp_cmdshell',0
    	reconfigure with override
    exec sp_configure 'show advanced options',0
    reconfigure with override
    
    --3.附加
    exec sp_attach_db NewTest,N'E:SQLNewTest.mdf',N'E:SQLNewTest_log.ldf'
    
  • 相关阅读:
    Jmeter之Bean shell使用(一)
    CSS知识点 2
    0523 CSS知识点
    0522 HTML表单 CSS基础
    0521 HTML基础
    0515线程
    0514 队列 管道 进程池 回调函数
    0510进程 multiprocess模块
    0509操作系统发展史 进程
    0507黏包
  • 原文地址:https://www.cnblogs.com/dunitian/p/6165998.html
Copyright © 2011-2022 走看看