Tutorials to .com

Tutorials to .com » Database » Sqlserver » End SQLSERVER database to the local directory

End SQLSERVER database to the local directory

Print View , by: iSee ,Total views: 11 ,Word Count: 350 ,Date: Tue, 25 Aug 2009 Time: 4:07 AM

End SQL SERVER database to a local directory

/ * database backup stored procedures * /
/ * Support for backup data from the server to the local machine * /
- Author: yoncen
CREATE PROCEDURE up_dbbackup
(
@ backup_db_name VARCHAR (128),
@ filename VARCHAR (128), / * back up the path + file name * /
@ 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 = database + @ backup_db_name + does not exist!
RETURN
END
ELSE
BEGIN
IF RIGHT (@ filename, 1) <> \ AND CHARINDEX (\, @ filename) <> 0
BEGIN
/ * Define symbol * /
DECLARE @ lFlag INT
EXECUTE @ lFlag = master .. xp_cmdshell DIR Z:
IF @ lFlag <> 0
BEGIN
/ * Client 192.168.2.45 to establish a completely shared directory db, specify a user name and password. Win98 users do not need a user name and password * /
EXECUTE @ lFlag = master .. xp_cmdshell NET USE Z: \ \ 192.168.2.45 \ db $ test / user: ca.atc \ test
IF @ lFlag <> 0
BEGIN
SELECT @ flag = server, create the directory failed!
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 = Database + @ backup_db_name + backup success!
RETURN
END
ELSE
BEGIN
SELECT @ flag = database backup path error!
RETURN
END
END


** The process is tested through the SQL SERVER7.0

** Thank http://www.myf1.net/bbs (Visual foxpro Help Forum)


Microsoft SQL Server Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.