This is generally used as the identification code and serves as the primary key for defining the table. The generated syntax allows you to customize the policy for generating this value.
Syntax:
Column definition generated {always | by default}
As {identity rules | using your rules}
Delete the table we created last time:
DB2 => drop table nomination
Create another table:
CopyCode The Code is as follows: Create Table nomination
(
Nominationid bigint not null primary key generated always as identity,
Nominee char (6) Not null,
Nominator char (6) Not null,
Reason varchar (250 ),
Nomdate date not null,
Categoryid integer not null,
Check (nominee! = Nominator) not enforced enable query optimization,
Foreign key categoryexists (categoryid)
References category (categoryid) on Delete restrict
)
Note that the values in the blacklist cannot be explicitly specified using insert or update.
Identity in DB2 also provides multiple policies. For details, you can check the DB2 Manual. The following is an example:
Delete the table we created last time:
DB2 => drop Table Category
Create a formCopy codeThe Code is as follows: Create Table Category
(
Categoryid integer primary key generated always as identity
(Start with 1 increment by 1 minvalue 0 maxvalue 999999999
No cycle cache 5 no order ),
Cateogryname varchar (50) not null,
Eligibility varchar (250)
)
you can find all the statements in identity in the black Chinese characters in the DB2 manual. They are all understood by the natural language at a glance.
sometimes you don't just want to fill in numbers, but you may want to process some letters. The following example of converting uppercase letters is for you:
DB2 => alter table category add column
uppercatname varchar (50) generated always as (upper (categoryname ))
these are described in the DB2 documentation.