DB2 9.5 and IBM Data Studio: Part 8: The SQL Builder Development Accelerators - The Rest of the Story

March 17, 2008

So far in this series about the IBM Data Studio integrated development environment (IDE) that’s available with DB2 Version 9.5 (DB2 9.5), I’ve shown you how to set up database connection objects and the actions that you can perform on them. In addition, I introduced you (in Part 2) to some of the features available in the Database Explorer view, and Part 3 and Part 4 gave you a full tour of overview diagrams. In Part 5, you learned how to point-and-click your way to OLE DB functions that can integrate data from external data sources that have an OLE DB provider. In Part 6, I showed you how easy it is to create an SQL statement using the IBM Data Studio SQL Builder. Part 7 introduced you to a set of rapid application development features within IBM Data Studio that takes your SQL development capabilities to a whole new level. Specifically, I introduced you to my favorite SQL Builder features: namely, SQL Assist, Content Tip, colorization, and the design-time parser. In this installment, I finish the tour of the SQL Builder features that help you get to an extreme development paradigm.

Things you have to do to follow the examples in this article...

I recommend for that all the multi-part articles I write that you start with Part 1 because I tend to build on the concepts and objects created in these series sequentially. For this article, I assume that you’ve read through Part 7 and your Database Explorer view looks like this:

More Development Assistance from the SQL Builder

In this section, I’ll detail the rest of the SQL Builder features that help boost productivity when you’re designing SQL statements using the FEMALEPERSONNEL2 query, which we built in Part 7 of this series.

Standard Editing Functions

IBM Data Studio comes with a number of basic text editing capabilities such as cut, copy, and paste, that users of word-processing software, spreadsheets, and more are accustomed to. As well, there are more advanced features such as undo, revert, format, indent, and so on. These features really come in handy when you are designing SQL statements.

To access the basic editing features (I’ll cover some of the more advanced ones in a bit), simply right-click within the design canvas of the SQL Builder:

Revert to Last Correct Source

Quite often, you’ll find yourself editing your SQL and making a mistake (or perhaps it’s just me). The Revert to Last Correct Source option comes in very handy. For example, add a D to the DEPARTMENT table name such that it looks like:

Now save this SQL statement (press Ctrl+S). You should receive an error message similar to this:

The SQL Builder is smart enough to see that this table doesn’t exist, and alerts you to this error when you try to save the statement. Click OK and then press Ctrl+S to override the real time parser in IBM Data Studio and save the query with the error.

Note: Make sure you save your SQL statement to enable this option. You can tell that your statement hasn’t been saved when an asterisk (*) prefixes the name of the SQL statement. When a statement is successfully saved (even with an error) the asterisk disappears, as shown below:

To have IBM Data Studio return the SQL statement to the last known version of it that worked, right-click in the SQL Builder and select Revert to Last Correct Source. IBM Data Studio will open a window that contains that last SQL statement that it successfully parsed. You can probably figure out what happens if you click OK at this point:

As you can see in the previous figure, IBM Data Studio changed the SQL statement back to the last time the SQL you wrote was valid. I like this feature because I often work off an SQL template, a stub file, or some sample SQL statement that I copied from the DB2 documentation or some article. If I mess it up, I know that I’ve got IBM Data Studio watching my back. What’s more, it seems that IBM Data Studio can remember that last version of your SQL statement that worked even after you close and subsequently reopen your SQL statement; that means the ‘state’ of the help engine persists across editing sessions!

Clear to Template

This option takes your SQL statement, as well as any changes you’ve made, and replaces it with the original template you worked with. For example, create the same error in the SQL statement that you just did in the previous section, but this time select the Clear to Template option.

If you recall from Part 5, we created an SQL statement using the SELECT template, and this is why the SQL statement reverted back to what’s shown below:

In this case, don’t save the SQL statement; just close it by clicking . By now you’re likely wondering why you would want to leverage this option. After all, you just spent time writing a full SQL statement, adding tables, specifying an ordering for the result set, and more.

In this example, we built the SQL statement from a simple SELECT statement. As you likely noticed, the built-in templates in the SQL Builder are very simple. The good news is that you can create customized templates that you can leverage within the SQL Editor (they are not available within the SQL Builder at this present time, but I expect that to change) and revert back to the template you defined. (I’ll introduce you to templates in the next section and discuss the SQL Editor in the next article.) If you recall, I’ve discussed how you would use a combination of the SQL Builder and the SQL Editor. For example, despite the fact that we created the FEMALEPERSONNEL SQL statement using the SQL Builder, you can subsequently open it using the SQL Editor and get all of the functionality that’s only available within the SQL Editor (such as templates) for your SQL statement:

In the future, these two editors may be merged into a single editor. One thing to note, however: there may come a point at which your SQL statement gets too complex for the SQL Builder and can only be opened in the SQL Editor. Those of us who have to write SQL statements daily as part of our jobs will likely feel the SQL Editor is the right trade-off between personal knowledge and design assistance.

Run your SQL

It’s good to know that you can run your SQL statement directly from the SQL Builder. This handy option enables you to quickly look at the result set for your SQL statements with a click of a button. Now think about extending such a benefit when you are in the Java perspective and writing a Java application. Forget about the fact that IBM Data Studio gives you SQL assistance when in the Java perspective, but the fact that you don’t have to write Java code or create a JUnit program to run your SQL is the big benefit here. These topics are outside the scope of this article, but this simple feature will prove to be very beneficial through the data lifecycle management process that I outlined in “DB2 9.5 and IBM Data Studio: Things I Couldn’t Tell You before DB2 9.5 Was Announced”.








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers