Search code examples
db2crudibm-midrangedb2-400

DB2 access specific row, in an non Unique table, for update / delete operations


Can I do row-specific update / delete operations in a DB2 table Via SQL, in a NON QUNIQUE Primary Key Context?

The Table is a PHYSICAL FILE on the NATIVE SYSTEM of the AS/400. It was, like many other Files, created without the unique definition, which leads DB2 to the conclusion, that The Table, or PF has no qunique Key.

And that's my problem. I can't override the structure of the table to insert a unique ID ROW, because, I would have to recompile ALL my correlating Programs on the AS/400, which is a serious issue, much things would not work anymore, "perhaps". Of course, I can do that refactoring for one table, but our system has thousands of those native FILES, some well done with Unique Key, some without Unique definition...

Well, I work most of the time with db2 and sql on that old files. And all files which have a UNIQUE Key are no problem for me to do those important update / delete operations.

Is there some way to get an additional column to every select with a very unique row id, respective row number. And in addition, what is much more important, how can I update this RowNumber.

I did some research and meanwhile I assume, that there is no chance to do exact alterations or deletes, when there is no unique key present. What I would wish would be some additional ID-ROW which is always been sent with the table, which I can Refer to when I do my update / delete operations. Perhaps my thinking here has an fallacy as non Unique Key Tables are purposed to be edited in other ways.


Solution

  • Try the RRN function.

    SELECT RRN(EMPLOYEE), LASTNAME
    FROM EMPLOYEE
    WHERE ...;
    
    UPDATE EMPLOYEE
    SET ...
    WHERE RRN(EMPLOYEE) = ...;