Optimizing SQL Server code in Toad for SQL Server

Hello. My name is Robert Pound. And I am a technical marketing manager.
Creating well written, efficient SQL code depends on several factors, including database architecture, environment, complexity of the request, and the skill of the developer. Thankfully, SQL Optimizer that is included in the Toad for SQL Server Development Studio can assist in your SQL efficiency.
For this video it is assumed that you are a developer and you have installed Toad for SQL Server Developer Suite on the system that you intend to develop from. Once Toad for SQL Server is installed on your system, you can utilize SQL Optimizer by simply right clicking on any database in your SQL Server Management Studio. And choosing Toad Optimize and finally Optimize SQL. This will open up the Toad tool and then SQL Optimizer. Of course, you can also directly open up Toad and SQL Optimizer from the environment.
You will be presented with two options. We will look at SQL Rewrites. But note you can also choose optimize your SQL by using Plan Control.
Here you can see the organization of the tool, where optimize SQL is the task that we are doing. SQL rewrite 1 is the project that is now opened. And SQL detail will display the SQL that we want to tune once it's loaded into the tool.
So from here we'll simply open from a file and choose the SQL that we want to tune.
Now you can SQL is in the Preview pane. And we have different options for running in optimization. However, we will simply choose Auto Optimize.
Before the optimization begins, you'll be presented with a series of questions. This helps the optimizer tune the optimization that happens. But we will just choose the defaults and choose Start Auto Optimize.
The tool analyzes syntax of the current statement as well as the associated tables and creates alternate SQL statements to test against the database. As alternates are run, the current champion will be moved to the top of the list. Several alternates will be evaluated. And this may run for several minutes, depending on the complexity of the code.
Once the analysis is complete, you're presented with a summary of the actual original SQL, breaking down the statistics, SQL information as far as how its optimized, complexity, et cetera, and then the results at the bottom of the screen. To get a more detailed look at the actual alternates themselves, we can come up to the Compare tab. And it will list out the original as well as the alternate and how it's affected.
So for instance, here at the bottom in this code, we can see that everything in the FROM clause obviously has been modified because it's highlighted in green here. It also has details in the Explain Plan itself as far as how it's affected.
So from here, you may want to formally report on your findings. We can come to the Report tab. And this will give us a report generating the metrics themselves, as well as the SQL code. This may be useful for team reviewing, etc.
So from here, once you have reviewed with the team, you can simply copy the new code, either from the Report or from the Compare tab. From here, you can utilize features such as Compare and Sync function that are highlighted in the video link below. For more information go to www.toadworld.com for the Toad family of products.
Hopefully this was helpful for you. Thank you for watching.

Learn how variables can be used in the Toad for SQL Server editor and in automation. This short video covers: prompting users for inputs in automation, creating variables from SQL statements, using "if" conditions for flow control, and the use of variables to output to the console, email, and filenames.

This video shows features of Log Reader in Toad for SQL Server, including a quick example of how to recover data that has been inadvertently updated. It also shows how to access Log Reader from SSMS or Toad, how to interpret the data in the reader, how to format and filter the data, and how to use the various tools in order to affect change in the database.

This 2 part video series explores the basics of automation in Toad for SQL Server. In part 2 we test the script we created in the previous video, and schedule it to run weekly once we are satisfied. We also explore the Job Manager after scheduling is completed.

This 2 part video series explores the basics of automation in Toad for SQL Server. Topics include: a simple automation scenario, different ways of accessing automation in Toad, automation settings, user interface, and input/output for a select to file activity.