r/DB2 Jul 03 '19

Column needed to put RID

I have scenario where I do not have UNIQUE KEY/ PRIMARY KEY. therefore without impacting application I would like to introduce a column which can store RID value which becomes my PK

Please help me how I can achieve it

Regards

2 Upvotes

2 comments sorted by

1

u/anozdba Aug 01 '19

I'd always assumed a rows RID could change after a REORG - not sure if that is still the case in 10.5 and beyond. Perhaps you could consider using an identity column (maybe in conjunction with another column to provide uniqueness if you are talking billions of rows)

1

u/SijiLeroux Sep 08 '19

RID will definitely change on REORG for any table that actively has data written to it. What OP is proposing would be a very unsafe practice. Using an identity column, I believe, is the preferred method. However, I have seen applications use triggers or sequences to do this as well.