How to rename a primary key

I'm trying to rename a primary key in a table by creating a new batch report. For instance, the original name of the first Entry No. is 10, I want to make it 1.
Can anyone help me how to achieve that?

Thanks in advance.

Best Answer

  • bbrownbbrown Member Posts: 3,268
    Answer ✓
    1. Create a holding table for the data. This should be a copy of the original table. It can be a temporary or real table.
    2. Copy the records to this holding table while deleting from the real table.
    3. Copy back to real table and update the primary key values before inserting,

    There are no bugs - only undocumented features.

Answers

  • bbrownbbrown Member Posts: 3,268
    Answer ✓
    1. Create a holding table for the data. This should be a copy of the original table. It can be a temporary or real table.
    2. Copy the records to this holding table while deleting from the real table.
    3. Copy back to real table and update the primary key values before inserting,

    There are no bugs - only undocumented features.
  • ACaignieACaignie Member Posts: 91
    Take care with relations! E.g. the G/L entry PK is also stored in the "G/L Entry - VAT Entry Link" table, so you will also have to change all entry numbers in related tables
  • AKAK Member Posts: 226
    That's what rec.RENAME is for.
  • bbrownbbrown Member Posts: 3,268
    Rec.Rename is fine when renaming a single (or a few) records. It is very inefficient when the need is to rename a large number of records.

    As mentioned above, you do need to pay attention to any table relations.
    There are no bugs - only undocumented features.
  • mustafaAlsoufimustafaAlsoufi Member Posts: 60
    Thank you all for your answers. Much Appreciated
Sign In or Register to comment.