Results 1 to 2 of 2
Thread: Synthetic vs Natural..
Jun 26, 2010, 19:10 #1
- Join Date
- Feb 2006
- Atlanta, GA, USA
- 59 Post(s)
- 0 Thread(s)
Synthetic vs Natural..
(Yeah, instead of using another person's question, i decided to make a seperate thread.)
My thought for an example/question would be calendar entries in something like Google Calendar.
Is there a natural key here? My thought says no, unless you force one on (userid,startdate,enddate,entryname).... but is that efficient? Does it violate the convention of avoiding business logic in keys (since theoretically, someone could create the same event twice)?
Jun 26, 2010, 21:59 #2
- Join Date
- Jul 2002
- Toronto, Canada
- 52 Post(s)
- 2 Thread(s)
whether or not a natural key exists depends on whether you want unique rows in this table
so (userid,startdate,enddate,entryname) looks pretty decent as a potential key
if you want to allow your table to have the same entryname for the same date range for the same user (i.e. a duplicate entry) then that key isn't unique enough
also, efficiency has nothing to do with uniqueness
the "convention of avoiding business logic in keys" is a new one on me, i'm not sure what you meant by that
so whether you want to allow a duplicate is what counts here, and you must pick your key column(s) accordingly
notice that if you didn't want the same entryname for the same date range for the same user, then the key you suggested is a good candidate for the primary key
but here's the thing -- suppose you were to use an auto_increment as the primary key for this table, you would still want to declare a UNIQUE key on (userid,startdate,enddate,entryname) as well!!
does any of the above rambling help?