创建备份设备mydiskdump,并备份数据库eduDB,建立SQL程序
时间: 2023-08-12 08:08:49 浏览: 216
创建备份设备mydiskdump:
```sql
USE master;
GO
EXEC sp_addumpdevice 'disk', 'mydiskdump', 'C:\Backup\mydiskdump.bak'
GO
```
备份数据库eduDB:
```sql
BACKUP DATABASE eduDB
TO mydiskdump
WITH FORMAT,
NAME = 'Full Backup of eduDB';
GO
```
建立SQL程序:
```sql
CREATE PROCEDURE usp_BackupDatabase @dbName NVARCHAR(50), @backupDevice NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sql NVARCHAR(500);
SET @sql = 'BACKUP DATABASE ' + @dbName + ' TO ' + @backupDevice + ' WITH FORMAT, NAME = ''Full Backup of ' + @dbName + '''';
EXEC sp_executesql @sql;
END
GO
```
使用示例:
```sql
EXEC usp_BackupDatabase 'eduDB', 'mydiskdump';
```
阅读全文