18
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective, and how to combine the tools in the Database Explorer with EGL for productive SQL development and testing,

The Eclipse Data Perspective and Database Explorer

Embed Size (px)

DESCRIPTION

The Eclipse Data Perspective and Database Explorer. This section describes how to use the Eclipse Data Perspective, and how to combine the tools in the Database Explorer with EGL for productive SQL development and testing,. The Data Perspective ***. - PowerPoint PPT Presentation

Citation preview

Page 1: The Eclipse Data Perspective and Database Explorer

®

IBM Software Group

© 2006 IBM Corporation

The Eclipse Data Perspective and Database Explorer

This section describes how to use the Eclipse Data Perspective, and how to combine the tools in the Database Explorer with EGL for productive SQL development and testing,

Page 2: The Eclipse Data Perspective and Database Explorer

2Last update: 12/04/2007

The Data Perspective******The Data Perspective allows you to access your data sources, and to view and add test rows, edit

your tables, create and test/execute SQL statements interactively. Access the Data Perspective from the Window menu

Window > Open Perspective > Other… > Data

The Data Perspective has only a few views and tools you will work with: Database Explorer

Shows Connections – which contain– Schemas and tables– Processing options

Data Output– Shows the results of running SQL queries

Data Project Explorer For Data Analysts

SQL Statement Wizard For building SQL statements interactively

*** Notes:*** Notes:The Data Perspective is only available if you have installedThe Data Perspective is only available if you have installedRBD v7.1 with IBM’s RAD, RDi or RDz productsRBD v7.1 with IBM’s RAD, RDi or RDz products

Page 3: The Eclipse Data Perspective and Database Explorer

3Last update: 12/04/2007

The Data Perspective – Connect to EGLDerbyR7All of your work in the Data Perspective is done through a database ConnectionConnection. In this course

our Database Explorer screen captures show four connections – your machine may have more or less, depending on the databases you have access to.

In the Data Perspective, you can define a new Connection, or reconnectreconnect to a database through an existing connection (like the one you’ve been using in debug, and used for the SQL Access Application import earlier in this course)

From the Database Explorer1. Right-click over EGLDerbyR7EGLDerbyR72. Select ReconnectReconnect Answer OK to prompts

You are “connected” and can: Expand folders Use the Data Perspective

Tools Views Wizards

2.

1.

Page 4: The Eclipse Data Perspective and Database Explorer

4Last update: 12/04/2007

The Data Perspective – Database Diagram So what can we do with the Data Perspective? Let’s start by having a look at our tables and

their relationships. From the Database Explorer

Expand the folders: EGLDerbyR7 > Schemas > EGL Right-click over EGL and select: Add to Overview Diagram Select only the EGL tables (elements) and check: Infer implicit relationships (if it’s not already checked)

Page 5: The Eclipse Data Perspective and Database Explorer

5Last update: 12/04/2007

The Data Perspective – Database DiagramThe Diagram Tool shows all of the tables selected through our connection,

and their relationships as defined by Primary/Foreign key SQL specifications. This allows us to understand things like how to join tables, and where data exists in relation to other table values.

We can also use the Diagram Tool to navigate in the Database Explorer Right-click over Customer and select:

Navigate > Show in > Database Explorer

Page 6: The Eclipse Data Perspective and Database Explorer

6Last update: 12/04/2007

Database Explorer – Exploring the Customer Table

The Database Explorer allows you to: View a table’s schema

Columns and Referential Integrity Constraints and Indexes

Through the Context Menu: Create the SQL data definition language statements to create the table From Data >

– View the table contents (Sample Contents)– Edit table values– Extract and load the table using a comma-delimited file

Exploring the Customer table

Database Explorer - Context Menu Options

Page 7: The Eclipse Data Perspective and Database Explorer

7Last update: 12/04/2007

Database Explorer – Sample ContentsWhen you are testing your SQL statements, it is extremely important to be able to view the row and column values in your tables. Sample Contents provides this view.

Note that this is essentially a Select * from <schema.table> If your table contains millions of rows… you will wait a long time to see your results

Even if your table contains say, only 50,000 rows So for production work, consider using the SQL Scrapbook to write a query that filters the result table (next topic)

Optional:Optional: Right-click over the Sample Contents rows, and select Save asSave as to your PC’s hard-drive. Note that you can do this with any results set – including the results of SQL queries you code and test.

Page 8: The Eclipse Data Perspective and Database Explorer

8Last update: 12/04/2007

Database Explorer – Open SQL ScrapbookAn SQL Scrapbook is a file that contains interactive - not embedded - SQL

statements (SQL statements without host-variables). These statements can be tested in the Data Perspective before embedding them in EGL data access functions. For complex SQL logic, this is recommended “best practice”.

To open and work with the SQL Scrapbook: Right-click over the database icon Select: Open SQL ScrapbookOpen SQL Scrapbook From the Create SQL Scrapbook Page wizard:

Expand your project and browse to:

EGLWeb/EGLSource/

SpecifySpecify a folder and a filename: /sql/myStmt

Page 9: The Eclipse Data Perspective and Database Explorer

9Last update: 12/04/2007

Database Explorer – Create and Run a SQL Scrapbook Statement

You can code your SQL statements using Content Assist – to get the table and table column names (Ctrl/Spacebar)

Right-click (context Menu)

Select Run SQL

View the Results

Right-click (context Menu)

Select Run SQL

View the Results

Page 10: The Eclipse Data Perspective and Database Explorer

10Last update: 12/04/2007

Database Explorer – Copy/Paste an Existing SQL Statement - 1 of 2 You can use the SQL Scrapbook to test your EGL/SQL statements out prior to testing them at

the EGL procedural logic level. Steps:

From the Workbench, click back over to the Web Perspective (but do NOT close the Data Perspective)

Open the CustomerLib.egl Find the GetBestCustomers(..) function shown below Expand the select statement – and copy the select order by clauses as shown

SelectAndCopyThis

Page 11: The Eclipse Data Perspective and Database Explorer

11Last update: 12/04/2007

Database Explorer – Copy/Paste an Existing SQL Statement - 2 of 2 From the Workbench, click back to the Data PerspectiveData Perspective If you still have your other SQL Scrapbook page open, select and delete your existing statement and

paste in the copied SQL code You could also follow the steps on a previous slide to create a new SQL Scrapbook page – then paste

the copied statement in Right-click and run the SQL Statement and view results in the Data Output tab

Page 12: The Eclipse Data Perspective and Database Explorer

12Last update: 12/04/2007

Database Explorer – Build SQL – New SQL Statement Database Explorer also has a simple, but effective SQL statement builder – that can provide assistance in creating your SQL statements:

Right-click over the database, and select New SQL Statement... Select the Statement template you wish to use, and click OK

From the middle-pane of the editor, right-click and select Add Table…

Select a table and press OKOK

Page 13: The Eclipse Data Perspective and Database Explorer

13Last update: 12/04/2007

Database Explorer – New SQL Statement

You will be shown a template statement with your selected table.1. Choose (check) Columns for your table

Each column is added to the SELECT clause

2. From the Conditions tab, select: Columns, OperatorType the value (if a literal) select AND/OR, etc.

Note that the common SQL Where Clause Operators are available from the combo-box

Page 14: The Eclipse Data Perspective and Database Explorer

14Last update: 12/04/2007

Database Explorer – Run New SQL Statement

Right-click in the top pane and select Run SQL. The Data Output Tab will show you any rows returned.

*** Notes:*** Notes:The row(s) you get

back may be different,

depending on the state of your table

rows after the preceding

workshops

Page 15: The Eclipse Data Perspective and Database Explorer

15Last update: 12/04/2007

Database Explorer – Table Edit – 1 of 2

Another very common requirement for SQL programming is to customize your test data

Right-click over a table and select: Data > Edit

Page 16: The Eclipse Data Perspective and Database Explorer

16Last update: 12/04/2007

Database Explorer – Table Edit – 2 of 2 The table editor allows you to:

Modify row and column values Add (insert) new rows Delete Rows Set field values to null

All values are saved (committed)or not (rolled-back) at once – Or when you press Ctrl/SCtrl/S

Page 17: The Eclipse Data Perspective and Database Explorer

17Last update: 12/04/2007

Data Perspective – Workshop If you haven’t been following along and doing all of activities shown on the previous slides with your instructor, do the following now :

Open the Data Perspective

Connect to: EGLDerbyR7

View all of the tables and their relationships through the Overview Diagram

Show the Customer table’s Sample Contents

Code a few simple SQL statements (or copy/paste from the CustomerLib) and run them in a SQL Scrapbook

Create a simple new SQL statement using the statement builder

Edit the Customer table: Add a few new rows Update some values Delete one or two rows Save your changes – Ctrl/SCtrl/S

Page 18: The Eclipse Data Perspective and Database Explorer

18Last update: 12/04/2007

Now that you have completed this topic, you should be able to:

Launch the Data Perspective Connect to a Data Source Use the Database Explorer to:

View tables and relationships View sample table rows and values Edit (create, update, delete) row values Test interactive SQL Code/Build SQL statements Generate Table DDL

Topic Summary

Summary