1:
你查一下 sql 手册, backup database 语句如下:
BACKUP DATABASE {database_name | @database_name_var}
TO <backup_device> [,...n]
[WITH
[BLOCKSIZE = {blocksize | @blocksize_variable}]
[[,] DESCRIPTION = {text | @text_variable}]
[[,] DIFFERENTIAL]
[[,] EXPIREDATE = {date | @date_var}
| RETAINDAYS = {days | @days_var}]
[[,] FORMAT | NOFORMAT]
[[,] {INIT | NOINIT}]
[[,] MEDIADESCRIPTION = {text | @text_variable}]
[[,] MEDIANAME = {media_name | @media_name_variable}]
[[,] [NAME = {backup_set_name | @backup_set_name_var}]
[[,] {NOSKIP | SKIP}]
[[,] {NOUNLOAD | UNLOAD}]
[[,] [RESTART]
[[,] STATS [= percentage]]
]
运行你的 query 就行了.
2: 最好用自动备份:
在sql 管理器中选择你的数据库,右键菜单中 all task 中选backup database,
再设置各个参数就行了.
你可以设置 schedule,比如每天12:00备份.这样SQL SERVER会自动备份.并在
Sqlserveragent中自动加入一备份 job.
如果想在程序中强制备份,调用系统存储过程 sp_start_job