Please help with INSERT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gdevelek
    New Member
    • Apr 2015
    • 3

    Please help with INSERT

    Using DB2 LUW v9.7, I have a table where the primary key is an identity column, generated by DEFAULT NO CYCLE . COL1 is the key, COL2, COL3 and COL4 are the remaining columns. An index is created on COL1. No other index exists.

    But I can't insert data into it.

    I write the insert like this, skipping the first column so DB2 will pick the value:

    insert into mytable (col2, col3, col4) values (1,6,'some_text ')"

    ...and I get this:


    DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned:
    SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the
    primary key, unique constraint or unique index identified by "1" constrains table "MYSCHEMA.MYTAB LE" from having duplicate values for the index key.
    SQLSTATE=23505

    What am I doing wrong???

    Thanks,

    George
  • gdevelek
    New Member
    • Apr 2015
    • 3

    #2
    I figured this out, please disregard it and sorry for your time.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Can you post your solution in case someone else runs into the same problem?

      Comment

      • gdevelek
        New Member
        • Apr 2015
        • 3

        #4
        Earlier I had inserted some data where the id column was provided explicitly. When later I attempted to insert data using the autoincrement feature, a conflict occurred when the "next value" was already taken by the initial data.

        Obviously that's a risk one takes when using the BY DEFAULT clause.

        Comment

        Working...