- 作者:zhaozj
- 发表时间:2020-12-23 10:58
- 来源:未知
/*數據庫備份存儲過程*//*支持從服務器備份數據至本地機器上*/-- 作者:yoncenCREATE PROCEDURE up_dbbackup(@backup_db_name VARCHAR(128),@filename VARCHAR(128), /*備份路徑+文件名*/@flag VARCHAR(60) OUTPUT)ASSET NOCOUNT ONDECLARE @sql NVARCHAR(4000),@par NVARCHAR(1000)IF NOT EXISTS(? SELECT * FROM master..sysdatabases??? WHERE name=@backup_db_name??? )BEGIN? SELECT @flag='數據庫'+@backup_db_name+'不存在!'? RETURNENDELSEBEGIN? IF RIGHT(@filename,1)<>'/' AND CHARINDEX('/',@filename)<>0? BEGIN? /*定義標誌*/ ? DECLARE @lFlag INT? EXECUTE @lFlag=master..xp_cmdshell 'DIR Z:'? IF @lFlag<>0? BEGIN??? /* 在客戶機192.168.2.45上建立一個完全共享目錄db,指定一個用戶名和密碼.Win98用戶不需要用戶名和密碼*/??? EXECUTE @lFlag=master..xp_cmdshell 'NET USE Z: //192.168.2.45/db$ test /user:ca.atc/test'??? IF @lFlag<>0??? BEGIN? ????? SELECT @flag='服務器創建目錄失敗!'????? RETURN??? END? END ? SELECT @par='@filename VARCHAR(1000)'? SELECT @sql='BACKUP DATABASE '+@backup_db_name+' TO DISK=@filename WITH INIT'? EXECUTE sp_executesql @sql,@par,@filename? EXECUTE master..xp_cmdshell 'NET USE Z: /DELETE'? SELECT @flag='數據庫'+@backup_db_name+'備份成功!'? RETURNENDELSEBEGIN??? SELECT @flag='數據庫備份路徑錯誤!'??? RETURNENDEND
**以上過程在SQL SERVER7.0下測試通過
**感謝http://www.myf1.net/bbs (Visual Foxpro幫助論壇)