Quantcast
Channel: Steve Hilker's Groups Activities
Viewing all articles
Browse latest Browse all 318

Iterative SQL Development

$
0
0

If you’re anything like me, then you probably don’t write the perfect SQL statement on your first try.  For me, it’s an iterative trial and error process before I get the result set just the way I want it.

Toad has a number of built-in features that help me work this way that I’ll share in this post.

Multiple result sets

Each time I run a query in Toad, I get a new result tab added to the Results window. In the screen shot below, I have 3 different result sets (named Set 1, Set 2, and Set 3) – one for each of the 3 times I executed a SQL statement.

By default, Toad will display 5 result sets before overwriting the oldest. Toad gives you a couple of different ways to manage these result tabs. First, you can change the default of 5 to some other value of your choice in the Toad options dialog. Select Database + Script Results and then select “Number of tabs to display” as shown below:

Increasing the value to 8 or 10 can be a handy way to stop overwriting your early attempts, but there’s another way, too.

Pinning Results

Toad allows you to pin result tabs. As I’m writing and tweaking my SQL, I’ll often feel that I’ve gotten it pretty close to what I want, but I might want to still try a few other alternatives. To keep from losing that “good” version, I can pin that result set by clicking on the tab. The pin icon will appear to show that you’ve marked that tab to not be overwritten:

So, using my example above if I were to run 4 more tries, Toad will not overwrite my Set 2. You can see in the screen shot below that Set 7 skipped overwriting Set 2:

What SQL did I run with that result?

Ok, so Toad will help me keep track and not lose the results that I liked but how do I remember what the SQL was that got those results? The SQL editor window is displaying my latest iteration, not the SQL that produced my “good” results. Well, lucky of us, Toad has us covered there, too.

In the lower right corner of the Results window is an up-arrow button:

Just click that button to expand the window to also show the SQL associated with the result set:

One last tip

All of the above is great and useful if you remember to use them. But sometimes, things just happen and you forget to pin a result set, your machine crashes, whatever. But you still need to get back to that SQL you had run. That’s when it’s time to use SQL Recall.

You can access SQL Recall from the View menu or just press Shift+F8:

By default, SQL Recall stores the last 100 SQL statements you’ve run. So, even if your system has crashed, you closed your SQL editor and forget to save your SQL, you want to pull up a statement that you ran potentially days ago, can get it back.

There are tons of time-saving and (sometimes it feels like life-saving) features like this within Toad.

Hope you found these useful.

Enjoy!

-Steve


Viewing all articles
Browse latest Browse all 318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>