ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

auto generating column

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • auto generating column

    hi friends,

    my boss is asking me to create a table where one column is supposed to be auto generating a sequential number. is this even possible? i have been reading through the reference manual and i cant find any field definition to do this.

    can some please tell me if this is even possible with the CREATE TABLE sql command? and if it is possible, how do i do this.


    many thanks in advance.
    idiot and stoopid with SQL

  • #2
    Re: auto generating column

    What manual are you using?
    Autoincrement constructs (identity columns) are available since release V5R1M0.
    (Sequences an other autoincrement construct were introduced with Release V5R3)

    Have a look at CREATE TABLE or ALTER TABLE Statement.

    Code:
    Create Table ....
    (MyId Integer Generated Always as Identity
            (Start with 1 Increment By 1),
    ... other columns
    When creating or changing tables with System i Navigator (wizard), define a numeric field and choose SET AS IDENTITY COLUMN.

    For more information check the following link (search for Identity)
    Create Table (Release 7.1)

    Birgitta

    Comment


    • #3
      Re: auto generating column

      thanks Birgitta, the identity column works.

      unfortunately, the db design that they wanted was only for 6-digits. do i tried using dec(6,0) to define the field.
      idiot and stoopid with SQL

      Comment

      Working...
      X