Save DB2 Query
QMF allows us to save a query for later use. A copy of query is not kept unless we save it. If a query is changed, the former query is lost unless we saved it.
Queries can be stored in the database with specific names. If we have created a query and want to save it for later, use the following procedure:
- Use command
SAVE QUERY X_query_name
at the command prompt. - Press Enter.
Rules for the names -
- Names can be up to 18 characters.
- Names may contain only letters of the alphabet, numbers, and the characters @, #, $, and underscore ( _ ).
- Names must begin with a letter, @, #, or $.
- X = Type of Object.
- Q—Query
- F—Form
- P—PROC
Steps to Save Query -
Scenario: - Steps to save the SQL query using QMF for future usage.
STEP-1: - Press PF6 to open the Query Editor from QMF Main menu screen.

STEP-2: - Once the query editor screen appears, type your SQL query on the blank screen (example below):

STEP-3: - Enter any one of the below command to save the query and press Enter.
- EXPORT QUERY AS query_name
- SAVE QUERY AS query_name

STEP-4: - Query is saved in the database with the name provided with userid before it. It shows like userid.query_name.
