I have a table
documents
(
year int not null,
number int not null,
document_types_id int not null,
...
)
The primary key is year + number + document_types_id.
I think that a better primary key would be year + document_types_id + number. Is there a way to reorder this composition (not columns in table, PK and FK combination) without deleting and recreation of PK, because this PK is used as a FK in many other tables.
Thanks.
Your foreign keys are referencing your primary key, so your foreign keys are 3-dimensional (year + number + document_types_id). If you are going to get rid of a dimension then even if you try to modify your primary key your constraints will tell you that you can’t get rid of the given column, so you should handle your foreign keys first and then you can modify your primary key. Steps:
Write all your foreign keys into a list to enable you to know which were the foreign keys before.
Get rid of all the foreign keys referencing your primary key
Modify/recreate your primary key
Recreate your foreign keys according to the new version of your primary key.