New Feature of SQL/400 in v5r2 OS/400: Automatic Generation of ID Columns

Source: Internet
Author: User
Some new features have been added to v5r2 OS/400 SQL. One of these new features is introduced here: Automatic Generation of ID columns.
The solution is as follows:
1. Enter the strsql command on the AS/400 command line.

2. Enter the following command to create a new table:
Create Table xqlib/employee1 (
Empno int generated always as identity,
Name char (20 ),
Salary int,
Bonus int
)
The predicate "generated always as identity" indicates that empno is an automatically labeled column.

3. input values using the insert statement:
Insert into xqlib/employee1 (name, salary, bonus)
Values ('bill)
Note:
The insert into statement cannot be used to specify a value for the empno column. By default, the value of this column starts from 1 and increments with 1 as the step size. You can also customize it according to your requirements, such:
"Generated always as identity (start with 100, increment by 10)", meaning "auto-marking column starts with 100, step size increases by 10"

View the result, as shown in:
----------------------------------------- Display data

Position to line .....
.... + .... 1 .... + .... 2 .... + .... 3 .... + .... 4 .... + .... 5 .... + .... 6 .... +...
---- Empno ---- name -------- salary ---- bonus
-------- 1 ---- George ------ 20,000 ---- 2,000
-------- 2 ---- Bill -------- 30,000 ---- 5,000
-------- 3 ---- Tom -------- 25,000 ---- 3,000
-------- 4 ---- Smith ------- 10,000 ---- 6,000
-------- 5 ---- black ------- 15,000 ---- 5,000
-------- 6 ---- grant ------- 25,000 ---- 5,000
-------- 7 ---- John -------- 25,000 ---- 5,000
* ******* End of Data ********

In the figure, the empno column automatically generates the ID column.

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.