Here I am looking a creating an online pilot logbook and wanted to
store the airfield information (currently just name). However all
airfields globally have a unique 4-letter ICAO identifying code which
would make sense to be the primary key. However as pasted into the
ticket, django doesn't like this - at least not in the admin interface.
Cheers,
Jonathan.
A slightly better (and real) example might be this: departments at a university are uniquely identified by a string, eg 'COMPSCI' for Computer Science, 'MATHS' for Mathematics, etc. These really are unique: there will never be another department whose code is 'COMPSCI' (ignoring mergers with other universities!).^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ But, see, you've just made my point for me -- it's nearly impossible to find an example where "meaningful" primary keys don't sometimes change. For example, at a previous job we had a database that keyed of a person's social security number, which we assumed would never change. Wrong -- a customer had her identity stolen and the government issued her a new SSN. It took three programmers nearly a day to replace her SSN in all the places it appeared with the new one! The point is, using "meaningless" unique IDs saves you from ever having to deal with these corner cases. Again, Django's not going to prevent you from shooting your future self in the foot; think of the hoops to jump through to use non-integer primary keys as a trigger lock. If you really know what you're doing, go ahead.
There are many cases where people are working closely to the database
like datawarehosing or if there is more then one application accessing
the database
some business rules need to better be programmed in the database
itself.
If I was in the situation of working closely to the database and most
of my relationships are bases on integers instead of some well
organised data structures, what would I do if I need to join, reason
abount values in agregation or apply businness rules based on values if
my most important data (data that sets the relationships and structure)
is just integers?
The problem with value changing is no problem if the database has all
the relationships set as needed so cascading updates/deletes happen
automaticaly at least when unig MSSQL server.
True, but I believe that's why we usualy set up 2 databases one
transactinal, where we stay put on to much normalization, relatinships,
indexes etc., and query oriented databases where this performance may
no matter that much since all the database updates are "nightly bach
updaes" anyhow, everything else is only queries.
As far as "needing keys that are not synthetic" what I'm sayng is that
many times I apply rules on a key value I also join on that key while
if it was integer I'll have 2 different keys one to join and one to
condition, multiply this by a couple and you get insted of a 100 lines
query a 200 lines query, that's all i'm saying. Now probably this is
just a silly asumption and I probably only need more experience on
doing it that way to see if it 's actualy true or not.