Basic SQL for DB2 (examples)

Topic

Description

General Notes

Strings are enclosed in single quotes (ex: 'My string') not in double quotes.

Connect/Use a Database

connect to <database name>

List structure of a Table

List Structure of a Table

DESCRIBE SELECT * FROM [table]

Tables

SQL commands

List tables in a Datbase:
Select name from sysibm.systables

Create a Table:
create table <table name>(<column name1> integer, <column name2> char(12), [etc...])

SQL commands

select * from <table name>

Insert a row.
insert into <table name> values (1,'hello') 

Update fields.
update <table> set <field> = 'New info' where <field> = 'Old Info'

AutoNumber for ID's

Example of having DB2 create an ID number

create table TESTING ( TEST_ID integer not null generated always as identity (start with 0, increment by 1, no cache) primary key, NAME varchar (30) )