use master IF OBJECT_ID('PSimpleBackup') IS NOT NULL BEGIN DROP PROC PSimpleBackup END GO CREATE PROC PSimpleBackup ( @db_name VARCHAR(200) ) AS BEGIN IF OBJECT_ID(@db_name + '..TMember') IS NULL BEGIN RETURN END IF db_id('SaiDao_Backup') IS NULL BEGIN CREATE DATABASE SaiDao_Backup END DECLARE @TableName VARCHAR(200) DECLARE TableList CURSOR FOR SELECT name FROM SaiDao_Backup..sysobjects WHERE type = 'U' OPEN TableList FETCH TableList INTO @TableName WHILE @@FETCH_STATUS = 0 BEGIN EXEC ('DROP TABLE SaiDao_Backup..' + @TableName) FETCH TableList INTO @TableName END CLOSE TableList DEALLOCATE TableList EXEC ('SELECT * INTO SaiDao_Backup..TMemberTransHist FROM ' + @db_name + '..TMemberTransHist') EXEC ('SELECT * INTO SaiDao_Backup..TMemberCardAcctHist FROM ' + @db_name + '..TMemberCardAcctHist') EXEC ('SELECT * INTO SaiDao_Backup..TMemberCardAccount FROM ' + @db_name + '..TMemberCardAccount') EXEC ('SELECT * INTO SaiDao_Backup..TMemberCard FROM ' + @db_name + '..TMemberCard') EXEC ('SELECT * INTO SaiDao_Backup..TMemberCourse FROM ' + @db_name + '..TMemberCourse') EXEC ('SELECT * INTO SaiDao_Backup..TMemberArrear FROM ' + @db_name + '..TMemberArrear') EXEC ('SELECT * INTO SaiDao_Backup..TMemberArrearEmployee FROM ' + @db_name + '..TMemberArrearEmployee') EXEC ('SELECT * INTO SaiDao_Backup..TMemberRepay FROM ' + @db_name + '..TMemberRepay') EXEC ('SELECT * INTO SaiDao_Backup..TMember FROM ' + @db_name + '..TMember') EXEC ('SELECT * INTO SaiDao_Backup..TItem FROM ' + @db_name + '..TItem') EXEC ('SELECT * INTO SaiDao_Backup..TCourse FROM ' + @db_name + '..TCourse') EXEC ('SELECT * INTO SaiDao_Backup..TMemberCardType FROM ' + @db_name + '..TMemberCardType') DECLARE @file VARCHAR(200) DECLARE @datetime DATETIME SELECT @datetime = getdate() SELECT @file = 'E:\SaiDao_Data_Bak\' + @db_name ; DECLARE @outut TABLE ( FOutput VARCHAR(1000) ) DECLARE @cmd VARCHAR(100) SELECT @cmd = 'mkdir ' + @file INSERT @outut EXEC xp_cmdshell @cmd SELECT @file = @file + '\' + @db_name + '_simple_' + CONVERT(VARCHAR(100), @datetime,112)+ SUBSTRING(CONVERT(varchar(100),@datetime,108),1,2)+ SUBSTRING(CONVERT(varchar(100),@datetime,108),4,2)+ SUBSTRING(CONVERT(varchar(100),@datetime,108),7,2) + '.bak' BACKUP DATABASE SaiDao_Backup TO disk = @file WITH FORMAT, NAME = '会员资料备份' DROP DATABASE SaiDao_Backup END GO exec PSimpleBackup 'dezhou_AXIN8fNFYgpa98V1'