惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
Schneier on Security
Schneier on Security
H
Help Net Security
PCI Perspectives
PCI Perspectives
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LINUX DO - 最新话题
GbyAI
GbyAI
IT之家
IT之家
TaoSecurity Blog
TaoSecurity Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
美团技术团队
T
Troy Hunt's Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Cloudbric
Cloudbric
A
About on SuperTechFans
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
H
Hacker News: Front Page
Forbes - Security
Forbes - Security
Webroot Blog
Webroot Blog
D
DataBreaches.Net
L
LangChain Blog
S
Schneier on Security
博客园_首页
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
News | PayPal Newsroom
Hacker News - Newest:
Hacker News - Newest: "LLM"
爱范儿
爱范儿
量子位
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
T
Threatpost
The Hacker News
The Hacker News
N
News and Events Feed by Topic
罗磊的独立博客
Spread Privacy
Spread Privacy
Hacker News: Ask HN
Hacker News: Ask HN

博客园 - yier

ZZ:修改sharepoint文档库文件类型显示图标(PDF,WinRAR) ZZ: How to remove 'Open in Windows Explorer' from the 'Actions Menu' zz: 如何查询SQL Server数据库的版本 zz: 关闭WIN2003关机事件跟踪程序 zz:MOSS內容資料庫的分配與管理 zz:CAML簡介 zz:全局化定制MOSS樣式 zz:貼幾個常用的MOSS樣式選擇器 ZZ:SharePoint常用目录介绍 ZZ:如何修改默认的site template大小 ZZ:JMeter使用指南 ZZ: Moving or Renaming the WSS Central Administration Content Database Search settings - Authentication failed because the remote party has closed the transport stream - yier zz: Calculated Columns - Displaying Images from oscar zz:如何更改列表项前的New标记的天数设置(days-to-show-new-icon ) from Jianyi ZZ: Uploads with SharePoint 2007 - Antivirus From Eric Cherng zz: SharePoint 2007 Folders from Eric Cherng [原创] 在dos命令行里面取当天是“星期几" ZZ: 如何禁止掉SharePoint页面个性化?(续) from kaneboy
zz: 如何移動已存在的SQL Server 2005中的user database
yier · 2009-09-07 · via 博客园 - yier

如何移動已存在的SQL Server 2005中的user database

有時候主機的硬碟空間不足或是因為要調整硬碟配置, 會動到資料庫的存放位置, 這裡有一篇 kb 在處理這個作業.

移動使用者資料庫

內容說明蠻詳細的, 我這裡簡單列出操作的方式:

1. 先找出該 db 的所有檔案, 利用以下指令(其中USERDB是假設的使用者資料庫名稱):
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'USERDB')

用戶插入圖片

(基本上至少會有兩個, 一個是放 data 的 mdf, 一個是放 log 的 ldf 檔案的所在位置)

2. 接下來將資料庫先離線:
ALTER DATABASE USERDB SET OFFLINE;
1).可能會花一些時間
2). USERDB 名称如若含有特别字符(空格,横线...) ,可以用“” 来包含.

3. 再來就是將資料庫的實體檔案搬移到指定位置, 這裡假設是 d:\sqldata\

4. 接下來就是將資料庫的 metadata 利用 alter database 指令進行調整:
ALTER DATABASE USERDB
    MODIFY FILE
 ( NAME = USERDB,
                  FILENAME = 'd:\sqldata\USERDB.mdf');
ALTER DATABASE USERDB
    MODIFY FILE
( NAME = USERDB_log,
                  FILENAME = 'd:\sqldata\USERDB_log.ldf');

5. 將資料庫上線:
ALTER DATABASE USERDB SET ONLINE;

6. 再次確認資料庫檔案所在位置:
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'USERDB')

用戶插入圖片

7. 進行資料庫測試, 例如 select 一些資料, 確認沒問題後, 即完成.

這個作業其實偶而會用到, 而且機會不低, 尤其是檔案大小成長速度快的, 非常實用, 給大家參考, 另外這篇雖然是 SQL Server 2005 的資料, 不過 SQL Server 2000 也同樣適用. 當然, 使用 backup / restore 的方式也沒問題, 只是用這個方式會快得多了. 另外使用 detach / attach db 的方式也是一種做法(後面資料也有)

如何使用 SQL Server 中的卸離和附加功能將 SQL Server 資料庫移到新位置http://support.microsoft.com/kb/224071/zh-tw