Getting started / 05
A table you can query.
Type STRSQL from the Main Menu. Enter each statement separately and press Enter.
Use a new schema name if LEARNSQL already exists.
CREATE SCHEMA LEARNSQL
CREATE TABLE LEARNSQL.CUSTOMER (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(30))
INSERT INTO LEARNSQL.CUSTOMER VALUES (1, 'Ada'), (2, 'Grace')
SELECT ID, NAME FROM LEARNSQL.CUSTOMER ORDER BY ID
The data display shows two rows: 1 / Ada and 2 / Grace. F3 returns to statement entry; F3 again returns to the menu. F9 recalls a statement. On a message, F1 shows SQLCODE and SQLSTATE.
SQL and objects share data
Tables are backed by physical files. SQL-created schemas are libraries, with journal objects.
DDS files can also be queried. Inspect your table with DSPFFD FILE(LEARNSQL/CUSTOMER).
Run one statement from CL
RUNSQL SQL('UPDATE LEARNSQL.CUSTOMER SET NAME = ''Ada Lovelace'' WHERE ID = 1') COMMIT(*NONE)
For a script, create a source member of type SQL, then run:
RUNSQLSTM SRCFILE(LEARN/QSQLSRC) SRCMBR(SETUP) NAMING(*SQL) COMMIT(*NONE)
Create QSQLSRC with CRTSRCPF and the SETUP member before running that command.
COMMIT(*NONE) makes these exercises immediate. Under commitment control, use
COMMIT or ROLLBACK explicitly; non-journaled tables cannot be changed under commitment control.
The SQL engine implements a subset of Db2 for i. Unsupported syntax reports an SQL message; validate migration queries and transaction behaviour against your target IBM i release.