I have a Products table, 2 options:
1. Let the user type the PK because some users can input Barcodes or no (in this case, the app will let to user free to input anything for example his own code conventions like Oreo Icecream IC-O) obviously, i need to add some validations to avoid PK with thousends of characteres and more.
2. Use the autoincrement PK and create another field for a "SecondaryCode" but for user this will be the primary key, some validations for SecondaryCode here too and this feels weird using a SecondaryCode like a PK.
Is there any very bad reason not to choose the first option? Theorically is good and more easy to manage but i don't feel comfortable exposing something important as a primary key. Maybe I'm missing something obvious.
Asked by Lund
(3 rep)
Jan 24, 2025, 02:21 AM
Last activity: Jan 24, 2025, 04:11 AM
Last activity: Jan 24, 2025, 04:11 AM