备份服务器端SQL SERVER数据库至本地目录
类别: MSSQL教程
/*???????浞荽???咿程*/
/*支持?姆??掌??浞?????至本地?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.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+’?浞莩晒Α’
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.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+’?浞莩晒Α’
RETURN
END
ELSE
BEGIN
SELECT @flag=’???????浞萋??藉e锗!’
RETURN
END
END
**以上咿程在SQL SERVER下?y??通咿
- 上一篇: 关于SQL Server 2000的安全配置
- 下一篇: Sqlserver中的一些技巧
-= 资 源 教 程 =-
文 章 搜 索