Creating an SQL statement

You can create an SQL statement using either the SQL Builder or the Create A New SQL Statement wizard. Both tools support the creation of SELECT, UPDATE, INSERT and DELETE statements. The SQL Builder also supports WITH (DB2 only) and FULLSELECT statements. Any statement that you create is stored in a file with the extension .sqx.

Prerequisite: Before you create your SQL statement, do one of the following actions:

To create an SQL statement using the SQL Builder:

  1. Switch to the Data Definition view in the Data perspective.

  2. Expand the project or folder that contains your database, and then expand the database nodes until you see the Statements folder.

  3. Right-click the Statements folder.

  4. On the pop-up menu, click New and then, on the submenu, click the command for the type of statement that you want to create.

  5. Type a name for your statement and then click OK.

Your statement is added to the Statements folder and opens in the SQL Builder. Complete the statement using the SQL Builder.

To create an SQL statement using the Create A New SQL Statement wizard:

  1. Click File > New > Other.

  2. In the New window, expand the Data folder, click SQL Statement, and then click Next.

  3. Use the pages in the wizard to define your SQL statement. If you need help completing the wizard, place the pointer in a field for which you want information and then press F1.

Overview of SQL statements
You can create and organize SQL statements against your database for use in testing and analysis of your design and also for use in an application.

Create A New SQL Statement wizard
The Create A New SQL Statement wizard and the SQL Builder both provide a visual interface for creating and executing SQL statements. You can use the wizard to create a simple SQL statement, or you can use the SQL Builder, which supports a wider range of statements. Statements generated by these tools are saved in a file with the extension .sqx.

SQL Builder
The Create A New SQL Statement wizard and the SQL Builder both provide a visual interface for creating and running SQL statements. You can use the wizard to create a simple SQL statement, or you can use the SQL Builder, which supports a wider range of statements.

Creating an SQL statement using the SQL scrapbook
The SQL scrapbook is similar to a basic text editor. You can open it and immediately start typing your SQL statement in it, without having to specify what kind of statement you want or importing any database tables into the workbench. You can also execute the SQL statement directly against the database.

Creating a SELECT statement
A SELECT statement retrieves data from a database and returns it in the form of a table. It can be embedded in an application or used interactively.

Creating a FULLSELECT statement
A FULLSELECT statement composes results from subqueries and sets of values to form a result table.

Creating an UPDATE statement
An UPDATE statement is used to update data in a table.

Creating an INSERT statement
Using an INSERT statement, you can insert rows from a values set or from a subquery result table into a database table.

Creating a DELETE statement
Use a DELETE statement to remove data from your database table.

Creating a WITH statement
A WITH statement is composed of one or more common table expressions and a SELECT statement. A common table expression defines a named result table that can be specified as a table in the FROM clause of a subsequent SELECT statement. This option is available only if you are using IBM DB2 Universal Database.

 

Parent topic

Working with SQL statements