For my country table, I used the country code as the primary key "AU, US, UK, FR" etc
For my currency table, I used the currency code as the primary key "AUD, GBP, USD" etc
I think what I did is ok, but another developer wants me to change all the primary keys to an int, because the country code, currency code might change sometime in the future he said. We just don't know that, well in this case he is right, his path is the safest path to take.
Should I change the primary keys to an int to be safe rather than be sorry? Can't I just keep it?
It is perfectly acceptable to use a varchar column as the primary key.
The primary key column(s) can be used (along with the foreign key) to create a reference between two tables. As shown earlier, the primary key column of one table can be the foreign key column in another table. Thus, it creates a link between the two tables.
In case the primary key is a multiple column one, then both columns need to be not null. While in theory you can use other fields as primary keys, integers are the easiest to manage, as well as being the fastest indexes available.
The data type of a primary key should be a numeric, an integer or a short, fixed-width character. Uniqueness. A primary key must have a unique value, which implies that no other row in the table has the same value in the column.
I would use the ISO codes with char columns.
If a country ever splits then you'd get new ISO codes (say SC, WL, EN) but UK will still be valid for historic data.
It's the same for currency. A transaction in 2000 would be in the currency at that time: French Francs, Deutschmarks, Belgium Banana but not Euro.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With