使用T-SQL进行数据库备份并检查该备份文件是否存在且作出相应处理
USE master
GO
EXEC sp_addumpdevice 'disk', 'AdvWorksData',
'E:\开发软件\数据库\SQl2005示例数据库\AdvWorksData.bak'
BACKUP DATABASE AdventureWorks
TO AdvWorksData
1.备份数据库语句:
EXEC sp_addumpdevice 'disk','数据库备份名称','文件路径'
BACKUP DATABASE 数据库名称
TO 数据库备份名称
2.sp_addumpdevice
代码
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [sys].[sp_addumpdevice] -- 1995/09/07 12:01
@devtype varchar(20), -- disk, tape, or virtual_device
@logicalname sysname, -- logical name of the device
@physicalname nvarchar(260), -- physical name of the device
@cntrltype smallint = null, -- obsolete: controller type - ignored.
@devstatus varchar(40) = null -- obsolete: device characteristics -ignored
as
declare @type_enum smallint -- devtype enumeration value
declare @returncode int
declare @devtypeIn varchar(20)
select @devtypeIn = @devtype
,@devtype = LOWER (@devtype collate Latin1_General_CI_AS)
-- An open txn might jeopardize a recovery.
set implicit_transactions off
if @@trancount > 0
begin
raiserror(15002,-1,-1,'sys.sp_addumpdevice')
return (1)
end
-- You must be SA to execute this sproc.
if (not is_srvrolemember('diskadmin') = 1)
begin
raiserror(15247,-1,-1)
return (1)
end
-- Check out the @devtype.
select @type_enum = (case @devtype
when 'disk' then 2
when 'tape' then 5
when 'virtual_device' then 7
end)
if @type_enum is null
begin
raiserror(15044,-1,-1,@devtypeIn)
return (1)
end
-- Check the args are not NULL.
if @logicalname is null
begin
raiserror(15045,-1,-1)
return(1)
end
-- Check to see that the @logicalname is valid.
EXEC @returncode = sys.sp_validname @logicalname
if @returncode <> 0
return(1)
if @physicalname is null
begin
raiserror
相关新闻>>
- 发表评论
-
- 最新评论 更多>>