Create a table in DB2 -- a table with an auto-incrementing Column

Source: Internet
Author: User

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.

 
 
  1. Create table test (id integer not null generated always as identity (startwith 1, increment by 1, no cache ),
  2. Name varchar (20 ))
  3.  
  4. Db2 => select * from test
  5.  
  6. ID NAME
  7. -------------------------------
  8.  
  9. 0 records are selected.
  10.  
  11. Db2 => insert into test (name) values ('wjz ')
  12. The DB20000I SQL command is successfully completed.
  13. Db2 => select * from test
  14.  
  15. ID NAME
  16. -------------------------------
  17. 1 wjz
  18.  
  19. 1 record selected.
  20.  
  21. Db2 => insert into test (name) values ('xlp ')
  22. The DB20000I SQL command is successfully completed.
  23. Db2 => select * from test
  24.  
  25. ID NAME
  26. -------------------------------
  27. 1 wjz
  28. 2 xlp
  29.  
  30. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.