A SQL Server job is nothing more than executing a specified script at a specified time. Here is how to create a job backup database with SSMS (SQL Sever 2008).
(0) Assume that the database you want to back up already exists before creating the job; secondly, you have already started the SQL Sever agent (usually closed)
(1) Create SQL Server Agent job
(1.1) Create a new job and output general information
As shown above: Enter the job name (such as: BackupJobTest), where the owner and category are default, enter the description (just like writing code to write comments, benefit others and self)
(1.2) Setting job execution steps
Click the Step Properties tab in the "Select Page" on the left, and click the "New" button
In the job step properties window, select the type (T-SQL), select the database to be backed up, and paste the debugged SQL backup script. Since I am also writing it for the first time, an example is posted here, and readers can refer to and modify it by themselves:
--将SQL脚本赋值给变量 declare @SqlBackupDataBase as nvarchar(1000) set @SqlBackupDataBase=N'BACKUP DATABASE YourDataBaseName TO DISK = ''E:\DBBackup\YourDataBaseName-'+ CONVERT(varchar(11),GETDATE(),112)+REPLACE(CONVERT(varchar(12),GETDATE(),108),':','') + ' .bak ''' -- backup file format: YourDataBaseName-20140626233410.bak print @SqlBackupDataBase -- print it out (for debugging convenience, it can be omitted) exec sp_executesql @SqlBackupDataBase -- call system stored procedure and execute SQL
Note: The third parameter of the CONVERT() function is the time style ID; the colon in the time is replaced with the REPLACE() function (because the file name cannot contain this character in Windows)
Time format and ID comparison table reference: W3school
(1.3) Set the job execution plan
In the Schedules tab, click the New button to create a new schedule:
After the setting is completed, click the "OK" button, and the other three properties "Alarm", "Notification", "Target" can be set by yourself if necessary, and will not be described here.
After completing the plan settings, click the "OK" button of the superior, and the job is created.
(2) Manually verify the correctness of job execution
Right-click the job just created under the job node ("BackupJobTest" in the figure), select 'Job Start Step (T)'
The execution result is as follows, indicating success:
Click "View History (V)" to view the log: