Results 1 to 5 of 5

Thread: Auto Increment of a column

  1. #1
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    304

    Auto Increment of a column

    I needed a column (named "ident") in a data table as an identifier.
    This column was not there at first.
    After I had created the column, I numbered the rows ascending using replace.
    Then I edited the "ident" field in the data workspace by checking "Auto increment".

    If I now add a new record, "ident" is set to 1, but the value of the highest number plus one should be taken.
    What else do I need to set?

    Grüße
    Georg

  2. #2
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,913
    Hi Georg,

    When you check 'Auto increment' in the Table Designer, it applies the AUTOINC Column Constraint this is an internal counter specific to that column and starts from 1 (* see below) for the next record to be added regardless of the current contents of existing records.

    * The full ALTER TABLE and CREATE TABLE SQL commands allow you to specify the NEXTVALUE: the value (not 1) to be given for the next record to be added.

    So you can use ALTER TABLE to specify 1 more than your current highest value for the next record to be added:

    Code:
    ALTER TABLE mytable MODIFY CONSTRAINT mycolumn SET AUTOINC NEXTVALUE myvalue
    Regards,

    Yvonne

  3. #3
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    304
    Sorry it seems it doesn't work.

    I give:
    ALTER TABLE ereignis MODIFY CONSTRAINT ident SET AUTOINC NEXTVALUE 3570

    My last record has the value 3569 in the ident column and
    I want the records to continue counting incrementally + 1 for new records.
    So if I do
    append blank
    (in the workspace console) and expect ident=3570. In reality I got, ident = 1

    Georg

  4. #4
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,913
    Hi Georg,

    Drop the autoinc then set it again with the nextvalue:

    Code:
    ALTER TABLE ereignis MODIFY CONSTRAINT ident DROP AUTOINC
    ALTER TABLE ereignis MODIFY CONSTRAINT ident SET AUTOINC NEXTVALUE 3570
    Regards,

    Yvonne

  5. #5
    Senior Member
    Join Date
    Feb 2012
    Location
    Germany, near Jena and Weimar
    Posts
    304
    Now it is ok.
    I dropped the autoinc for ident too before... but via via menu

    Thankful
    Georg

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us