备份服务器端SQL SERVER数据库至本地目录
类别: 数据库教程
*???????浞荽???咿程*/
/*支持?姆??掌??浞?????至本地?C器上*/
CREATE PROCEDURE up_dbbackup
(
@backup_db_name VARCHAR(128),
@filename VARCHAR(128), /*?浞萋??将文件名*/
@flag VARCHAR(60) OUTPUT
)
AS
SET NOCOUNT ON
DECLARE @sql NVARCHAR(4000),@par NVARCHAR(1000)
IF NOT EXISTS(
SELECT * FROM master..sysdatabases
WHERE name=@backup_db_name
)
BEGIN
SELECT @flag=’?????臁?+@backup_db_name+’不存在!’
RETURN
END
ELSE
BEGIN
IF RIGHT(@filename,1)<>’’ AND CHARINDEX(’’,@filename)<>0
BEGIN
/*定柳?苏I*/
DECLARE @lFlag INT
EXECUTE @lFlag=master..xp_cmdshell ’DIR Z:’
IF @lFlag<>0
BEGIN
/* 在客???C192.168.2.45上建立一??完全共享目??db,指定一??用?裘?和密瘁.Win98用?舨恍枰?用?裘?和密瘁*/
EXECUTE @lFlag=master..xp_cmdshell ’NET USE Z: \\192.168.2.45db$ test /user:ca.atctest’
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+’?浞莩晒Α’
RETURN
END
ELSE
BEGIN
SELECT @flag=’???????浞萋??藉e锗!’
RETURN
END
END
**以上咿程在SQL SERVER下?y??通咿
/*支持?姆??掌??浞?????至本地?C器上*/
CREATE PROCEDURE up_dbbackup
(
@backup_db_name VARCHAR(128),
@filename VARCHAR(128), /*?浞萋??将文件名*/
@flag VARCHAR(60) OUTPUT
)
AS
SET NOCOUNT ON
DECLARE @sql NVARCHAR(4000),@par NVARCHAR(1000)
IF NOT EXISTS(
SELECT * FROM master..sysdatabases
WHERE name=@backup_db_name
)
BEGIN
SELECT @flag=’?????臁?+@backup_db_name+’不存在!’
RETURN
END
ELSE
BEGIN
IF RIGHT(@filename,1)<>’’ AND CHARINDEX(’’,@filename)<>0
BEGIN
/*定柳?苏I*/
DECLARE @lFlag INT
EXECUTE @lFlag=master..xp_cmdshell ’DIR Z:’
IF @lFlag<>0
BEGIN
/* 在客???C192.168.2.45上建立一??完全共享目??db,指定一??用?裘?和密瘁.Win98用?舨恍枰?用?裘?和密瘁*/
EXECUTE @lFlag=master..xp_cmdshell ’NET USE Z: \\192.168.2.45db$ test /user:ca.atctest’
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+’?浞莩晒Α’
RETURN
END
ELSE
BEGIN
SELECT @flag=’???????浞萋??藉e锗!’
RETURN
END
END
**以上咿程在SQL SERVER下?y??通咿
- 上一篇: 用SQL语句来建立跟踪的问题
- 下一篇: SQL SERVER中的一些技巧
-= 资 源 教 程 =-
文 章 搜 索