drop proc pr_backup_db
end
go
create proc pr_backup_db
@flag varchar(20) out,
@backup_db_name varchar(128),
@filename varchar(1000) --路徑+文件名字
as
declare @sql nvarchar(4000),@par nvarchar(1000)
if not exists(
select * from master..sysdatabases
where name=@backup_db_name
)
begin
select @flag=’db not exist’ /*數據庫不存在*/
return
end
else
begin
if right(@filename,1)<>’\’ and charindex(’\’,@filename)<>0
begin
select @par=’@filename varchar(1000)’
select @sql=’BACKUP DATABASE ’+@backup_db_name+’ to disk=@filename with init’
execute sp_executesql @sql,@par,@filename
select @flag=’ok’
return
end
else
begin
select @flag=’file type error’ /*參數@filename輸入格式錯誤*/
return
end
end
GO