Free Newsletters:
DatabaseJournal  
DBANews
Database Journal
Search Database Journal:
 
HOME News MS SQL Oracle DB2 Access MySQL PostgreSQL PHP SQL Etc Scripts Links Discussion
internet.com

» HOME
» NEWS
» FEATURES
» SERIES
MS SQL
Oracle
MS Access
MySQL
DB2
» RESOURCES
Products
Scripts
Links
» DISCUSSION
» TECH JOBS

Marketplace Partners
Be a Marketplace Partner




internet.commerce
Be a Commerce Partner
Promotional Products
Auto Insurance Quote
Compare Prices
Online Shopping
Imprinted Gifts
Corporate Gifts
KVM Switch over IP
Condos For Sale
Memory
KVM over IP
KVM Switches
Web Hosting Directory
Online Education
PDA Phones & Cases




MySpace Joins eBay, Yahoo in Open Profile Push

News Corp. Unit Under Fire for Ties to Hacker

Are Non-PC Devices Hurting 'Net Innovation?

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Linked Data Planet Conference & Expo

CA ERwin® Data Modeler Proven database design and modeling. Efficiently analyze, design and deploy effective database solutions. Whitepaper: Manage SQL Server Deployments
Try it free: CA ERwin® Data Modeler


Solaris 8 Migration Assistant
Rapidly move your Solaris 8 application environments to new systems running Solaris 10 with the Solaris 8 Migration Assistant. Reduce migration risk while taking advantage of increased performance, reliability and security of the latest SPARC hardware platforms and Solaris 10 OS. »

 
Sun Eco Innovation: Good for Business, Good for the Environment
A complete solution to help you optimize and refresh your datacenter while properly recycling equipment and eliminating eWaste, including money-saving promotions to lower hardware acquisition costs. »

 
Sun Eco Innovation: Power Calculators
Power consumption has increasingly become a priority in customer's minds when purchasing new systems or storage. Sun's Power Calculators provide data on power consumption of Sun products allowing IT managers to better plan the power requirements in the datacenter to achieve better energy and cost savings. »

 
Optimize the Web Tier: Consolidate to Get More Performance in Less Space and Lower Power Consumption
Expansion in the Web tier is generally accomplished by adding more servers whenever extra capacity is needed. As the pool of servers grows larger, however, the complexity of the environment can grow exponentially. »
Related Articles
DB2 9.5 and IBM Data Studio Part 3: Overview diagrams - the basics
DB2 9.5 and the IBM Data Studio - Part 2
DB2 Viper II and the IBM Data Studio Developer Workbench

Production Manager (hands on)
Aquent
US-MA-Cambridge

Justtechjobs.com Post A Job | Post A Resume
DB2
February 5, 2008
DB2 9.5 and IBM Data Studio: Building an SQL Statement
By Paul Zikopoulos

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, I showed you 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 this part, I’m going to show you how easy it is to leverage the SQL editor in IBM Data Studio to quickly and easily build an SQL statement.

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

I recommend that you start with Part 1 because I tend to build on the concepts and objects created in this series sequentially. For this article, I assume that you’ve at least created the SAMPLE database (using the db2sampl –xml –sql command). Of course, I’m assuming that the SAMPLE database appears in the Database Explorer view and that you have a data development project created. You can use the DatabaseJournalProject that I quickly showed you how to create in Part 5, or create a new one, as shown below:

You can see in the previous figure the OLE DB function that we created in Part 5 of this series.

Building an SQL Statement using the IBM Data Studio

IBM Data Studio comes with a built-in tool called the SQL Builder for creating SQL statements. This tool can be invoked from different parts of the integrated development environment (IDE); for example, it’s available in various wizards for building routines, and it can be started on its own to build standalone SQL statements.

The steps that follow outline how to build the following query using the SQL Builder:

SELECT PAULZ.DEPARTMENT.LOCATION, PAULZ.EMPLOYEE.EMPNO, 

 PAULZ.EMPLOYEE.FIRSTNME, PAULZ.EMPLOYEE.LASTNAME, 

 PAULZ.EMPLOYEE.PHONENO
FROM PAULZ.DEPARTMENT, PAULZ.EMPLOYEE

WHERE PAULZ.DEPARTMENT.DEPTNO = PAULZ.EMPLOYEE.WORKDEPT 

AND PAULZ.EMPLOYEE.SEX = 'F' 

ORDER BY LASTNAME DESC, FIRSTNME DESC

This query returns a predefined number of attributes that are joined from the EMPLOYEE and DEPARTMENT tables for all female employees registered for a fictitious company.

To build an SQL statement using the IBM Data Studio SQL Builder, perform the following steps:

1.  Select the SQL Scripts folder from your project, right-click, and select New->SQL Statement.

2.  The New SQL Statement window opens. Select a project from the Project name drop-down list that you want to associate this SQL statement with; for our example, use the DatabaseJournalProject project. In addition, enter FEMALEPERSONNEL as the name for this SQL statement in the Statement name field, and select the SQL builder radio button. The default SELECT option in the Statement template field is fine since we are building a SELECT SQL statement. Now click Finish.

In the previous figure, you can see that you can use the Project name drop-down list to select any existing data development project that you’ve created in IBM Data Studio. If you want to create a new one, or don’t have one, click New and this will launch the New Data Development Project wizard.

IBM Data Studio provides templates for multiple SQL statements. The default template creates a SELECT statement, but as you can see in the previous figure, you can use the Statement template drop-down list to select one of several templates provided.

Also, note in the previous figure that you have the option to create your new SQL statement using the SQL Editor as opposed to the SQL Builder. While the SQL Editor lets you build your SQL statement, this option doesn’t give you all of the assistance features associated with the SQL Builder. For this article, we’ll stick with the SQL Builder. As you get more experienced with IBM Data Studio, you can use SQL Editor to build other SQL statements. In the end, you’ll decide just how much ‘hand holding’ you want; either facility will give you a productivity boost.

3.  Depending on the way you configured your database connection object, you may be prompted to enter a valid set of credentials to connect to the database for which the database connection object was created. If this is the case, enter in the credentials for a user account with access to the data server, and click OK.

If the connection is successful, IBM Data Studio will create a template for the type of SQL statement you are trying to create, as shown below:

4.  Right-click in the To add a table… pane and select Add Table.

5.  The Add Table window pop-up appears. Select the EMPLOYEE and DEPEARTMENT tables, and then click OK. (Use the CTRL key to select multiple tables from the Add Table window - or add them one at a time.)

You may have noticed that the Add Table window has a Table Alias field. As its name implies, you can use this field to give a table an alternative name; however, when you add multiple tables to the SQL Builder at the same time, this field becomes inactive.

If you are dealing with complex table names, or simply want to refer to your tables using an alias name, you need to select them one at a time and assign each an alias name.

For this example, you can optionally remove the DEPARTMENT table that you’ve already added (simply click to select it and press Delete), and add the DEPARTMENT table again using an alias of DEPARTMENTALPERSONNEL.

The SQL Builder should now look like this:

You can see that the SQL Builder provides visual cues to certain relationships in each column. For example, a primary key is represented by and a foreign key relationship by . You can also hover over any column in the SQL Builder and hover help will let you know the underlying data types (especially useful when creating SQL statements that contain a join):

Go to page: 1  2  Next  

Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

DB2 Archives

Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.
Webcast: Five Virtualization Trends to Watch. Produced for HP, Citrix, and Intel.
Download: SQL Compare Pro 6--The fastest, easiest way to compare and synchronize two databases.
Data Sheet: IBM Information Server Blade
Whitepaper: Enterprise Information Integration--Deployment Best Practices for Low-Cost Implementation


Latest Forum Threads
DB2 Forum
Topic By Replies Updated
database files move????? db2dba 1 March 25th, 09:02 AM
Missing objects in sysproc schema bocap 0 March 3rd, 07:44 PM
Linked Server - Connect to db2 rayan127 0 February 22nd, 02:10 PM
Difference in DB2 Date returned Indresh_Chadha 1 February 19th, 01:24 PM







JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES