WEB开发网
开发学院数据库MSSQL Server T-SQL 备份和还原 阅读

T-SQL 备份和还原

 2009-09-14 00:00:00 来源:WEB开发网   
核心提示: Code/*Author:Terry.Sai.M.J 浪客 Location:BeiJingDateTime:GETDATE()Description:还原master数据库*/--Bakup master databaseBACKUP DATABASE [master] TO DISK=

Code

/*
Author:Terry.Sai.M.J 浪客
Location:BeiJing
DateTime:GETDATE()
Description:还原master数据库
*/

--Bakup master database
BACKUP DATABASE [master] TO DISK='F:\Documents and Settings\Administrator\桌面\master.bak' WITH FORMAT

--Test for creating database
CREATE DATABASE db
ON PRIMARY
(
    NAME=db_data,
    FILENAME='F:\Documents and Settings\Administrator\桌面\db_data.mdf'
)
LOG ON
(
    NAME=db_log,
    FILENAME='F:\Documents and Settings\Administrator\桌面\db_log.ldf'
);

--开始菜单->运行->services.msc->找到sqlserver服务以及对应的实例->找到对应服务的路径 (F:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn \)->在运行中输入cmd->cd 刚才的目录->输入sqlservr.exe -m(单用户模式登录)->然后打开 SSMS->新建一个查询(注意只有一个连接,不要连接SSMS数据库引擎了)->然后运行下面的sql

RESTORE DATABASE master FROM DISK='F:\Documents and Settings\Administrator\桌面\master.bak'

--还原db,
CREATE DATABASE db
ON PRIMARY
(
    NAME=db_data,
    FILENAME='F:\Documents and Settings\Administrator\桌面\db_data.mdf'
)
LOG ON
(
    NAME=db_log,
    FILENAME='F:\Documents and Settings\Administrator\桌面\db_log.ldf'
)
FOR ATTACH

DROP DATABASE db

上一页  1 2 3 4 5 6 7  下一页

Tags:SQL 备份 还原

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接