0
次のスクリプトを作成しましたが、の符号が@command
であるためにエラーが表示されます。誰も私がこのエラーを取り除く方法を提案することができますか?T-SQLスクリプトを使用して日付別のバックアップファイルを作成する方法
USE msdb;
GO
--add a job
EXEC dbo.sp_add_job
@job_name = N'FullBackup';
GO
USE msdb;
GO
--add jobsteps to jobsteps
DECLARE @fileName VARCHAR(90);
DECLARE @db_name VARCHAR(20);
DECLARE @fileDate VARCHAR(20);
DECLARE @commandtxt VARCHAR(100);
SET @fileName = 'D:\SQL server\BackUp\';
--SET @db_name = 'AdventureWorks_';
SET @fileDate = CONVERT(VARCHAR(8), GETDATE(),112);
SET @fileName = @fileName + @db_name + RTRIM(@fileDate) + '.bak';
SET @commandtxt = N'''BACKUP DATABASE [AdventureWorks2012] TO DISK =N''' + @fileName + ''' WITH INIT';
EXEC sp_add_jobstep
@job_name = N'FullBackup',
@step_name = N'Weekly Full Backup',
@subsystem = N'TSQL',
@command = 'BACKUP DATABASE [AdventureWorks2012] TO DISK =N''' + @fileName + ''' WITH INIT',
@retry_attempts = 5,
@retry_interval = 5;
GO
--Create a Schedule for this job, backup, occurs once a week each friday at 11:59
EXEC sp_add_schedule
@schedule_name = N'WeeklyBackup1',
@freq_type = 8,
@freq_interval = 32,
@freq_recurrence_factor = 1,
@active_start_time = 235900;
GO
--attach the schedule to the job
EXEC sp_attach_schedule
@job_name = N'FullBackup',
@schedule_name = N'WeeklyBackup1';
GO
EXEC dbo.sp_add_jobserver
@job_name = N'FullBackup';
GO