It is very easy to create a table in DB2. But how can I create a table with an auto-incrementing column? The following describes how to create an auto-incrementing table in DB2 for your reference.
- Create table test (id integer not null generated always as identity (startwith 1, increment by 1, no cache ),
- Name varchar (20 ))
-
- Db2 => select * from test
-
- ID NAME
- -------------------------------
-
- 0 records are selected.
-
- Db2 => insert into test (name) values ('wjz ')
- The DB20000I SQL command is successfully completed.
- Db2 => select * from test
-
- ID NAME
- -------------------------------
- 1 wjz
-
- 1 record selected.
-
- Db2 => insert into test (name) values ('xlp ')
- The DB20000I SQL command is successfully completed.
- Db2 => select * from test
-
- ID NAME
- -------------------------------
- 1 wjz
- 2 xlp
-
- Two records are selected.
Edit recommendations]
DB2 database commands
Four file formats for DB2 data movement
Implementation of DB2 column-to-row
DB2 Incremental backup method
DB2 offline backup test instance