================备份数据库=================
--完整备份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_20070908.bak'
--差异备份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Df_20070908.bak'
With Dferential
--日志备份默认截断日志
Backup Log NorthwindCS
To disk='G:\Backup\NorthwindCS_Log_20070908.bak'
--日志备份不截断日志
Backup Log NorthwindCS
To disk='G:\Backup\NorthwindCS_Log_20070908.bak'
With No_Truncate
--截断日志不保留
Backup Log NorthwindCS
With No_Log
--或者
Backup Log NorthwindCS
With Truncate_Only
--截断之后日志文件不会变小
--有必要可以进行收缩
--文件备份
Exec Sp_Helpdb NorthwindCS --查看数据文件
Backup Database NorthwindCS
File='NorthwindCS' --数据文件逻辑名
To disk='G:\Backup\NorthwindCS_File_20070908.bak'
--文件组备份
Exec Sp_Helpdb NorthwindCS --查看数据文件
Backup Database NorthwindCS
FileGroup='Primary' --数据文件逻辑名
To disk='G:\Backup\NorthwindCS_FileGroup_20070908.bak'
With init
--分割备份到多个目标
--恢复时候不允许丢失任何个目标
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_1.bak'
,disk='G:\Backup\NorthwindCS_Full_2.bak'
--镜像备份
--每个目标都是相同
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Mirror_1.bak'
Mirror
To disk='G:\Backup\NorthwindCS_Mirror_2.bak'
With Format --第次做镜像备份时候格式化目标
--镜像备份到本地和远程
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Mirror_1.bak'
Mirror
To disk='\\192.168.1.200\Backup\NorthwindCS_Mirror_2.bak'
With Format
--每天生成个备份文件
Declare @Path Nvarchar(2000)
Set @Path ='G:\Backup\NorthwindCS_Full_'
+Convert(Nvarchar,Getdate,112)+'.bak'
Backup Database NorthwindCS
To http://www.hack58.net/Article/html/3/7/2008/mailtdisk=@Path
--从NoRecovery或者
--Standby模式恢复数据库为可用
Restore Database NorthwindCS_Bak
With Recovery
--查看目标备份中备份集
Restore HeaderOnly
from Disk ='G:\Backup\NorthwindCS_Full_20070908.bak'
--查看目标备份第个备份集信息 ......
==================Kill掉访问某个数据库的连接=============
2: CREATE PROC KillSpid(@DBName varchar)
3: AS
4: BEGIN
5: DECLARE @SQL varchar
6: DECLARE @SPID int
7: SET @SQL='DECLARE CurrentID CURSOR FOR
8: SELECT spid FROM sysprocesses WHERE dbid=db_id('''+@DBName+''') '
9: FETCH NEXT FROM CurrentID INTO @SPID
10: WHILE @@FETCH_STATUS <>-1
11: BEGIN
12: exec('KILL '+@SPID)
13: FETCH NEXT FROM CurrentID INTO @SPID
14: END
15: CLOSE CurrentID
16: DEALLOCATE CurrentID
17: END