Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

SQL and XQuery tutorial for IBM DB2, Part 1: Introduction to Aroma and SQL

Pat Moffatt (pmoffatt@ca.ibm.com), Information Management Program Manager, IBM Academic Initiative, IBM
Pat Moffatt is the Information Management Program Manager for the IBM Academic Initiative. Through the Academic Initiative program, she ensures that appropriate Information Management resources are made available to help faculty integrate Information Management software into their curriculum. To learn more about this program, visit www.ibm.com/university/data.
Bruce Creighton (bcreight@ca.ibm.com), Skills Segment Planner, IBM
Bruce Creighton is a Skills Segment Planner in the Information Management Education Planning and Development department. In this role, he plans investment in educational content and balances the investment between areas where IBM can attain revenue and those where the requirement for skills development are important enough to provide free education.
Jessica Cao, Training Tools Developer, IBM
Jessica Cao is an Arts and Science and Computer Science student at McMaster University. She expects to complete her combined honours degree in April 2009. Jessica is working in IBM Toronto lab's DB2 Information Management Skills Channel Planning and Enablement Program to take advantage of her interest in programming, editing, and writing.

Summary:  This tutorial introduces readers to the Aroma database to apply Structured Query Language (SQL) and XML Query (XQuery) knowledge to solve typical business questions. Also included are detailed instructions for installing DB2® and the Aroma database. This tutorial is Part 1 of the SQL & XQuery tutorial for IBM DB2 series.

View more content in this series

Date:  03 Aug 2006
Level:  Introductory PDF:  A4 and Letter (214 KB | 26 pages)Get Adobe® Reader®

Activity:  25391 views
Comments:  

Before you start

About this series

This tutorial series teaches basic to advanced SQL and basic XQuery topics and shows how to express commonly asked business questions as database queries by using SQL queries or XQueries. Developers and database administrators can use this tutorial to enhance their database query skills. Academic Initiative members can use this tutorial series as a part of their database curriculum.

All the examples in this document are based on Aroma, a sample database that contains sales data for coffee and tea products sold in stores across the United States. Each example consists of three parts:

  • A business question, expressed in everyday language
  • One or more example queries, expressed in SQL or XQuery
  • A table of results returned from the database

This guide is designed to allow participants to learn the SQL language and XQuery. As with any learning, it is important to supplement it with hands-on exercises. This is facilitated by the table definitions and data.

For students using this as part of an academic class, obtain from your instructor the instructions to connect to the Aroma database and learn about any differences between the guide and your local set up.

This tutorial was written for DB2 Express-C 9 for UNIX®, Linux® and Windows® (formerly known as Viper).


About this tutorial

This tutorial introduces participants to the Aroma database, especially the retail group of tables, table definitions, sample data, and the relationship between tables.

These tables were created to show an environment where:

  • There are few tables
  • Column names use the analyst's vocabulary
  • Columns are reflective of the natural dimension of the business

This is a typical, small data warehouse using a star schema. The other type of database is Online Transaction Processing (OLTP). OLTP databases contain transacations at the most granular level.

This tutorial also introduces the basics of SQL and suggests some typical business questions that IBM DB2 9 can be used to answer.


System requirements

To use this tutorial to the fullest, you should have IBM DB2 9 installed. Download DB2 Express-C, a no-charge version of DB2 Express Edition for the community that offers the same core data features as DB2 Express Edtion and provides a solid base to build and deploy applications. You will also need to install the Aroma database, which can be downloaded from here.

Installing DB2 Express-C 9

To install DB2 9, follow these steps (default options should be used unless otherwise specified):

  1. Navigate to the folder containing the downloaded file - db2exc_viper_WIN_x86.zip (we will assume the file is downloaded to the C:\DownloadDirector folder).
  2. Unzip the file.
  3. Find setup.exe in the unzipped folder and double-click on it. The DB2 Setup Launchpad will appear.
  4. Within the DB2 Setup Launchpad, click on Install a Product from the panel on the left.
  5. Click on Install New under DB2 Express.
  6. In the installer, click Next to view the License Agreement. You will need to Accept the agreement to continue and click Next.
  7. Choose a Typical installation and click Next.
  8. Confirm that you plan to "Install DB2 Universal Database Express Edition on this computer and save my settings in a response file" and click Next.
  9. Verify the installation directory and click Next.
  10. In the "Configure DB2 instances" screen, click Next.
  11. In the "User Information" screen, set the Domain to None -- use local user account using the pull-down menu, use db2admin as the User name, and set a password.
    (Optionally, you can select the LocalSystem account, but there are limitations introduced if this option is used. Click the Help button to learn more.)
  12. Make sure the checkbox Use the same user name and password for the remaining DB2 services is checked and click Next.
  13. Click Next to skip the "Prepare the DB2 tools catalog" screen.
  14. To simplify installation, uncheck Set up your DB2 server to send notifications and click Next.
  15. Verify that the Enable operating system security checkbox is checked. Leave the DB2 administrators group as the default value DB2ADMNS and leave DB2 users group as the default value DB2USERS. Click Next.
  16. Click Finish to start the DB2 product installation when you reach the "Start copying files and create response file" screen.
  17. When the installation is complete, a window with the message "Setup is complete" will appear. Click Finish to complete the installation procedure.
  18. A window entitled "DB2 First Steps" will now appear. Click Create profile. Your Web browser will open a page called DB2 First Steps. This tutorial contains many useful links to information on DB2, but it will not be used during this tutorial. Close your Web browser and continue with this tutorial.

Installing the Aroma database

  1. Ensure DB2 Express-C 9 is installed.
  2. Start the Command Window from the Start menu ==> all Programs ==> IBM DB2 ==> Command Line Tools ==> Command Window.
  3. Execute create_aroma.bat in the Command Window.
    Note: Don't forget to move to the directory where the batch file is located using the cd command.
  4. Two files, create.txt and report.txt, will be created. Edit report.txt and compare to the expected results below:
           TABLE                                          RECORDS
           ---------------------  -----------
           aroma.class                          9
           aroma.deal                            9
           aroma.line_items        182
           aroma.market                  17
           aroma.orders                    27
           aroma.period                    821
           aroma.product                59
           aroma.promotion        194
           aroma.sales                          69941
           aroma.store                        18
           aroma.supplier                9

XML support

XML and basic XQueries will be introduced in Part 7 of this series. To support XML, the aromadb database was created with the statement:

			db2 create db aromadb using codeset utf-8 territory us

Note the specification of UTF-8 as the codeset for the database. The use of XML features is restricted to a database that is defined with codeset UTF-8 and has only one database partition. When creating your own databases in the future, don't forget to include this parameter or your database won't support XML features!

1 of 12 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management, XML
ArticleID=151316
TutorialTitle=SQL and XQuery tutorial for IBM DB2, Part 1: Introduction to Aroma and SQL
publish-date=08032006
author1-email=pmoffatt@ca.ibm.com
author1-email-cc=
author2-email=bcreight@ca.ibm.com
author2-email-cc=
author3-email=jcao@ca.ibm.com
author3-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.