Skip to main content

SQL job actions

What is it?​

This page lists the job types supported by the SQL Agent and shows reference examples for each one. Use it to:

  • Confirm which job action fits the database platform you target.
  • Compare configuration options for a single job type at a glance.
  • Find a worked example to base a new job on.

For the full field-by-field reference, see SQL Job Details in the Concepts online help.

Job action quick reference​

Job actionUse it forField reference
MS SQL DTExecRunning SSIS packages with dtexecFields for MS SQL DTExec
MS SQL JobTriggering SQL Server Agent jobsFields for MS SQL Job
MS SQL ScriptRunning ad-hoc T-SQL or script filesFields for MS SQL Script
MySQLRunning script files against MySQLFields for MySQL
OracleRunning script files against Oracle with SQL*PlusFields for Oracle
Other DBODBC or OLE DB connections to any other databaseFields for Other DB

:::tip How to use this page Each job-type section uses tabs to switch between configuration variants. Pick the tab that matches your scenario rather than scrolling through every variant. :::

How the agent runs every job action​

These rules apply across the job actions. Differences between actions are noted in each section.

TopicBehavior
Account the job runs asIf the job's Windows User ID is set, the job runs as that Windows user and the Password field holds that user's Windows password. The agent does not pass a database password in that case. If Windows User ID is empty, or begins with USE SERVICE ACCOUNT, the job runs as the SQL Agent service account.
Encrypted valuesAny part of the server name, password, database name, script statements, script path, output file path, other options, Oracle parameters, connection string, or environment variable names and values can be entered between <SmaEncrypt> and </SmaEncrypt>. The agent decrypts each such part before it builds the command.
Environment variablesEach action uses them differently: MS SQL Script sets them in the job's process environment; MySQL defines each one as a MySQL user variable (@NAME); Other DB replaces $(NAME) in the script text with the value; Oracle and MS SQL DTExec do not use them.
Encrypt ConnectionApplies to MS SQL Script only, where the agent adds -N to the sqlcmd command line. The other actions do not use it.
Client programsMS SQL Script, MS SQL DTExec, MySQL, and Oracle run SqlCmd.exe, DtExec.exe, MySql.exe, and SqlPlus.exe. Each program must be installed and on the PATH of the account the job runs as. Other DB and MS SQL Job connect from inside the agent.

MS SQL DTExec​

Run SQL Server Integration Services (SSIS) packages through dtexec. Choose the connection type tab that matches how your packages are stored — file system or SQL Server.

For the field reference, see Fields for MS SQL DTExec in the Concepts online help.

Use FILE when the SSIS package is stored on the file system.

Defining MS SQL DTExec with FILE Connection


MS SQL Job​

Start a SQL Server Agent job and control how the SQL Agent monitors it. Each tab shows a different monitoring strategy or option.

For the field reference, see Fields for MS SQL Job in the Concepts online help.

The SQL Agent reports the job's final status when it finishes.

Defining MS SQL Job to Monitor until Completion

How the agent monitors an MS SQL Job​

  • Monitor only. When the job definition is set to monitor only, the agent does not start the SQL Server Agent job. It watches the job and reports its outcome. For every MS SQL Job, the agent checks the job's status every 10 seconds.
  • Monitor end time. The end time is a number of hours after the start of the schedule date. When that time is reached, the agent reports the OpCon job as finished with exit code 0, even if the SQL Server Agent job is still running. The SQL Server Agent job is not stopped.
  • Retry Attempts. If the agent connects but the SQL Server is not available, it waits 5 minutes and tries again, up to the number of retry attempts in the job definition (default 0). An error while connecting is not retried. The 5-minute wait is fixed.

The agent reports the SQL Server Agent job's outcome as the exit code:

Exit codeSQL Server Agent job outcome
0Succeeded
1Failed
2Retry
3Cancelled
4In progress
5Unknown

MS SQL Script​

Run T-SQL against MS SQL Server. The script can be written in line in the job definition or pulled from a .sql file. Pick the tab that matches how you want the script and any runtime values supplied.

For the field reference, see Fields for MS SQL Script in the Concepts online help.

The script is written directly in the job definition.

Defining MS SQL Script with In Line Script

:::note UseScriptExitCode When the Use Script Exit Code option is enabled and the job uses an inline script statement, the agent wraps the statement in EXIT(statement) when calling sqlcmd, causing sqlcmd to return the query result as its process exit code. This option has no effect when the job uses a script file path instead of an inline statement. In every case, the job's exit code is the sqlcmd exit code; the agent always adds -b, so sqlcmd returns an error exit code when a statement fails. :::

:::note EncryptConnection When the Encrypt Connection option is enabled in the job definition, the agent adds the -N flag to the sqlcmd command line, which tells sqlcmd to use an encrypted connection for the SQL Server session. The option applies to MS SQL Script only. :::


MySQL​

Run a script file against MySQL. The agent runs the file in Script File Path; it does not run statements entered in the job definition. The example tabs show the most common configurations.

For the field reference, see Fields for MySQL in the Concepts online help.

:::note MySQL default port When no port is specified in the job definition, the agent does not pass a port to MySql.exe, so the MySQL client's own default port is used. :::

Connects to MySQL on the default port.

Defining MySQL with Default Port


Oracle​

Run a script file against Oracle with SQL*Plus (SqlPlus.exe). The agent runs the file in Script File Path; it does not run statements entered in the job definition. The tabs cover the most common parameter and connection patterns.

For the field reference, see Fields for Oracle in the Concepts online help.

Writes job output to a specified file path and applies a password overwrite.

Defining Oracle with Output File Path and Password Overwrite Option


Other DB​

Connect to any database through ODBC or OLE DB. Use this job action when the database isn't covered by one of the dedicated job types above. The three sub-sections below correspond to the three connection methods.

For the field reference, see Fields for Other DB in the Concepts online help.

DSN Name connections​

Connect through a Data Source Name configured on the agent machine.

In Line Script with environment variables — first part.

Defining Other DB using DSN Name with In Line Script and Environment Variables 1

OleDB Connection String​

Connect by supplying a full OLE DB connection string in the job definition.

OleDB connection string with an in-line script.

Defining Other DB using OleDB Connection String with In Line Script

ODBC Connection String​

Connect by supplying a full ODBC connection string in the job definition.

ODBC connection string with an in-line script.

Defining Other DB using ODBC Connection String with In Line Script


FAQs​

What is the difference between MS SQL Job and MS SQL Script? Use MS SQL Job to trigger and monitor a pre-existing SQL Server Agent job. Use MS SQL Script to run T-SQL directly via sqlcmd — either an in-line script or a .sql file. MS SQL Script does not require a pre-existing SQL Server Agent job.

How does the agent retry a failed connection? Only MS SQL Job jobs retry. If the agent connects but the SQL Server is not available, it waits 5 minutes and tries again, up to the job definition's Retry Attempts (default: 0). The 5-minute wait is fixed. An error while connecting is not retried. See How the agent monitors an MS SQL Job.

What port does MySQL use if I leave the port field blank? The agent does not pass a port, so the MySQL client uses its own default port.

What does "Use Script Exit Code" do for MS SQL Script jobs? When enabled and the job uses an inline script statement, the agent wraps that statement in EXIT(statement) when calling sqlcmd, causing sqlcmd's process exit code to reflect the query result. In every other case the job's exit code is still the sqlcmd exit code.

Can MySQL or Oracle jobs run statements entered in the job definition? No. For MySQL and Oracle, the agent runs only the script file in Script File Path. Put the statements in a script file.