dragonwell
Programmer
For instance a "State/Province" table, where all we really care about is a 2-character code, and a long name.
The options I see are:
1. use the 2-char code for the PK and FKs in other tables
2. Put in an integer column for the PK and use that for FKs in other tables, and put a unique index on the 2-char code and use the 2-char code in the app's business-logic code.
Really with the State/Province example it seems obvious to just use the natural key, but with other more app-spcific types, I'm not sure which way to go. It seems that if you use the 2-character code for a pk, then you run out if you get over 104 types.
For instance, my app has a JobType table, with maybe 15 row at most. I know I want a unique, 2-character code for each that I will use in the business-logic, as well as a varchar(50) for the actual name of the job-type. The question is, do I simply make the 2-cahr code the PK, or add an int column for the PK - i.e. - " a key unrelated to the data"
?
Hope that makes sense.
-d
The options I see are:
1. use the 2-char code for the PK and FKs in other tables
2. Put in an integer column for the PK and use that for FKs in other tables, and put a unique index on the 2-char code and use the 2-char code in the app's business-logic code.
Really with the State/Province example it seems obvious to just use the natural key, but with other more app-spcific types, I'm not sure which way to go. It seems that if you use the 2-character code for a pk, then you run out if you get over 104 types.
For instance, my app has a JobType table, with maybe 15 row at most. I know I want a unique, 2-character code for each that I will use in the business-logic, as well as a varchar(50) for the actual name of the job-type. The question is, do I simply make the 2-cahr code the PK, or add an int column for the PK - i.e. - " a key unrelated to the data"
?
Hope that makes sense.
-d