Summary
This tutorial helps you get started with Automation by giving you an overview of the Automation module and then guiding you through the process of creating a basic script.
In this tutorial you will learn:
Watch a video version of this tutorial: Getting Started with Automation.
Note: The Automation module is disabled if Toad was installed with the Prohibit saving passwords option selected.
Toad provides an Automation utility that allows you to easily script database activities and schedule them using the windows scheduler. In this way, database tasks can be automated to save you time. Toad Automation can increase your productivity by allowing you to automate tasks that you perform repeatedly.
The Benefits of Using Automation
* Did You Know *Opening the Automation WindowThere are several ways to open an Automation window.
|
To get started with Automation, open an Automation window by selecting Tools | Automation.
The Automation window consists of a Toolbox pane (along the left side of the window), a design pane (top half of the window), and a details pane (bottom half of the window).
Toolbox—Stores the Automation activities. Click an activity in the Toolbox to add it to the script design pane. Activities are listed by category: Database, File, or System.
Script Design Pane—Graphically displays the script as a workflow. Use the script design pane to build an Automation script. Drag an activity to the design pane to add the activity to a script.
Note: You must drag the activity to anAdd Activity icon in the Automation workflow. When you see the activity's icon displayed in the workflow, release the mouse button.
Details Pane—Displays an activity’s settings. Click an activity in the design pane to display its configurable settings in the details pane. Use the details pane to specify the settings for each activity in the script.
With the Select to File activity still selected in the script design pane, view the details pane. The details pane allows you to configure settings for the selected activity. The input fields change depending on which activity is currently selected in the design pane.
Note: The Activity Input tab is the tab where you will specify most of an activity's settings.
Click next to the Select to File activity. Toad uses this icon to indicate that more information is required to complete the activity. Click or hover over the icon to display the missing information. Use this icon to help you determine which input fields are required.
Note: This icon is also used to indicate a validation error, for example, when referencing a variable that has not been created yet.
Now click the Settings icon in the design pane. The details pane changes to display input fields for the script’s settings. You can use this area to specify script error handling, logging level, and run environment settings.
Click the Stop on Error button, if not already selected. This instructs the script to stop if an error is encountered.
Note: You can also enable or disable the Stop on Error option for each individual activity. If you know that a particular activity will have an error, you can disable the Stop on Error option for just that activity. This option is located on the Activity Info tab for each activity.
In addition to selecting the Stop on Error option, enabling the Send email when error occurs and Attach log file to email options is also preferred. This can be very useful if your script encounters an error. Enabling your script to send an email notification on error, as well as on success, helps you to feel confident that your processes are running as expected.
If you choose to enable these options, you must specify email settings. To specify email settings, click the Compose Email button.
In the Activity Input tab, in the first text box, select a database connection, or use the default. The default database connection for each database activity is always the currently-active open connection. To select a different database connection, click and browse to a different connection.
Note: If you schedule a script to run against a password-protected database for which you did not save the password in Toad, the script will error. To save the password, right-click the connection in the Connection/Navigation Manager and select Properties. Enter the password and select the Save Password option.
Tip: For Snowflake connections, it is considered best practice to use only the Snowflake user account authentication when creating Automation scripts to avoid unnecessary workflow interruptions.
You now have a complete activity, with input, output, and database connection specifications. You can save and reuse this activity in other scripts by saving the activity as a template. To do this, right-click the activity (after configuring all the settings) and select Save As Template. Enter a name for your template and click OK to save it.
Your template now appears in the Toolbox in the Templates category.
While the script is running, Toad displays your script’s execution progress in the Log tab. The message “Done” indicates script execution is finished.
If you require a more detailed Log, you can change the logging level. In the Settings Activity Input tab, select Verbose from the Logging level drop-down list to create a more detailed log.
Note: If you want to change the location of the Log file, select a new location in the Logging folder input field.
Toad allows you to specify both a Test database connection and a Production database connection for each script. Toad also allows you to specify which connection to run your script against when the script executes. Both of these settings are made in the script’s settings. This feature allows you to easily test your script in a test environment before running your script in the production environment.
To specify a test and a production database, make the selections in the Connection text box under Test environment and Production environment in the Settings Activity Input tab. To select which of these databases to run your script against, select Test or Production from the Select environment drop-down list.
If you remember from the overview of the Automation window, Toad allows you to enable or disable each activity in a script. This can be helpful when building a script, as it allows you to test one particular activity at a time by disabling the other activities.
In the Activity Info tab, click Disabled to disable the Select to File activity. Notice that the activity now appears shaded in the design pane. To enable the activity again, click Enabled, or right-click the activity in the design pane and select Enabled.
Once you have thoroughly tested your script, you can schedule it.
The Job Manager window opens and a task properties dialog displays. The task properties dialog is pre-populated with the information required to run your script as a scheduled task. You only need to schedule it. (The Job Manager uses the Windows Scheduler.)
Now you have learned how to increase your productivity by using Toad Automation to handle your repetitive reporting and deployment tasks!
Other Toad Automation tutorials are available. To see more examples and to learn how to build other types of scripts to automate everyday tasks, start with the following:
Summary
This tutorial walks you through the process of automating the task of exporting query results to simple Excel reports. You will create three different, and very useful, simple Excel reports.
In this tutorial you will learn:
Watch a video version of this tutorial: Automate Exporting Data to Excel.
After creating a result set in Toad, you may need to send the results to your end users. The easiest way to create a report containing query results is to export the data to an Excel file by right-clicking the data grid and selecting Quick Export | File | Excel File. This action creates a basic Excel spreadsheet containing the result set from the data grid.
If you want to create more than a basic spreadsheet and automate the process, Toad Automation helps you build a variety of Excel reports, from simple worksheets to complex and attractive Excel reports.
In this introduction to automating Excel reports, you will learn how to automate the process of exporting data to a variety of simple Excel reports.
Note: To learn how to get started with Automation, see Getting Started with Automation.
Click the Select to File activity in the Database Activities pane of the Toolbox, or drag the activity from the Toolbox to the Automation design window.
Click in the Name field to select a location and enter a name for your new Excel file, or you can select an existing file.
Note: To specify more-detailed options for the Excel file, click the Export options button.
Select Overwrite if you want to overwrite the file.
Note: If you did not add a suffix, you can deselect Overwrite to append a new worksheet to the Excel file with each script execution.
That was simple, wasn't it. Now move on to the next example to learn how to create a slightly more complex Excel report.
Suppose you want to create a new report each week from the same query while retaining the previous week’s results. In this case, you want to append each week’s results as a new worksheet to a single Excel file. This is an excellent option if you want to compare the results each week (or each day, month, etc.) to see how the data is changing. (And Toad has several data compare features in the application to let you do that.)
Select Append timestamp to named worksheet. This will append the date and time (that the data was exported) to the base worksheet name. Click OK to save your settings and close the dialog.
Click
The output of this script is one Excel file containing multiple worksheets. Each worksheet contains a result set from one execution of the script. And each worksheet name records the date and time the result set was exported.
Another variation of the multi-page Excel report is to export the results of multiple queries. Each worksheet in the Excel file will be populated with the result set of a different query. This can be accomplished by using a SQL file that contains multiple SQL statements as the input file.
Click Export options and make sure the Worksheet name field is blank.
Note: If the Worksheet name field is not blank, your script will export both result sets into the named sheet, and the second result set will overwrite the first.
Click
The output of this script is one Excel file containing multiple worksheets. Each worksheet contains the result set of a different query.
Note: To learn how to export the result sets of multiple queries into a single worksheet (using Automation), see Automate Complex Excel® Reports.
As you can see, with Toad Automation you can easily create basic Excel reports, but with a few more script configurations and the use of templates, you can also create attractive and more complex reports. To learn how, see the following tutorials on Automating Excel Reports.
See Schedule Your Script to learn how to schedule the Automation script.
Use Database Automation Activities
Use Automation to schedule a single script to run reports and queries, save results in Excel spreadsheets, and distribute results to the business community via email. You can schedule scripts that perform long-running tasks to run when database activity is light.
You can also use variables in automation scripts. With variables, you can update information that may be different each time you run the script, such as the department name, revenue, fiscal quarter, or product name. See Using Variables in Automation for more information.
For example, assume you are an analyst at Nick's Flicks movie rentals. You need to run inventory and movie rental reports on a daily basis and distribute them to managers of the inventory department. Using Toad, you can create an automation script that runs the reports, exports them to Excel spreadsheets, and emails the spreadsheets to the inventory department everyday at 2:00 AM.
Troubleshooting: You must surround a variable name with the # sign (for example, #sleep#).
Notes:
To automate tasks
Click Settings (icon) in the script design window and specify script settings. Enter settings in the bottom pane. Review the following for additional information:
Activity Input Tab | |
Stop or continue on Error |
Select Stop On Error to stop the script if an error occurs. |
Send email when error occurs |
Select this option to send an email on script error. If selected, you must also click Compose Email to compose the email message and to edit the Email Server Settings. Note: When you specify the error email settings, Toad saves your settings and uses them in all subsequent automation scripts. |
Use relative path to find files |
Select to convert all local file paths to relative paths in all activities in the script (network file paths remain unchanged). This is useful if you want to share your automation scripts with colleagues or place them on a shared network. Toad makes the change the next time you run or save the script. If you deselect this option later, the script reverts back to the original absolute paths. Note: Toad deselects this option when publishing a script to Intelligence Central. |
Embed files into Automation script |
Embeds Toad input files into the script. This makes it easier to share the script with colleagues. Important: To use this option, deselect it, build your script, select input files, then re-select this option. This allows Toad to collect and save the input file paths. This option embeds Data Compare, Important: Files linked using the Link to File option in the Select to File, Execute Script, and Select to Editor with Results activities are not embedded [.sql, Editor (.tef), and Query Builder (.tsm) files)]. Toad embeds the files the next time you run or save the script. If necessary, at a later time you can deselect this option and then re-establish links to the original files. Note: Toad selects this option when publishing a script to Intelligence Central. |
Truncate log |
Select to overwrite the log file each time the script runs. |
Selected environment |
Use this area to specify a "test" database connection and a "production" database connection and then easily switch between the two.
Note: The Connection field under both environments defaults to the currently-active open connection. Variable names
|
Activity Info Tab | |
Name |
Enter a script name. |
To build a script, single-click an activity in the Toolbox, or drag an activity from the Toolbox to the Automation script design window. Repeat this process to add additional activities to your script.
Note: You must drag the activity to , then release the mouse button after you see the activity's icon replace .
Click an activity in your script workflow in the design window and then specify the activity's properties in the details pane (bottom pane). Repeat this process for each activity in your script. For a step by step tutorial on building an Automation script, see Getting Started with Automation.
See the following topics for details about each activity and its properties:
Tip: You can save an activity and its settings as a template to reuse in other scripts. Right-click the activity in the design window and select Save As Template. After you create the first template, a Templates toolbox displays.
Note: Click Settings in the design window at any time to go back and review the Automation script settings.
|
Add an automation script to the current project in the Project Manager. The script is automatically placed in the project's Automation Scripts folder. |
|
Save an automation script (.tas) in a folder on a local or network drive. |
|
Run an automation script before scheduling it. The script executes once and the execution log is displayed in the Log window. Resolve any problems that cause activities to fail, or disable failed activities before scheduling the script. Tips:
|
Publish | Publish script to Toad Intelligence Central. |
|
Schedule an automation script in the Job Manager. You can schedule a script to execute once or to run periodically at a defined interval. See Execute and Schedule Automation Scripts for more information. |
Important: To rename an Automation script file, do so through Toad (File | Save File As), not through Windows Explorer. Renaming a script file using Toad ensures that log files are created correctly and properly synced with their scripts.
Tips:
© ALL RIGHTS RESERVED. 이용 약관 개인정보 보호정책 Cookie Preference Center