Thursday, August 17, 2006

In interviews I need to know how well the candidate knows databases and start off by going back to basics.  After establishing that the candidate knows that the 'R' in RDBMS stands for 'Relational', I follow it up by asking for a definition of 'Relation'.  I will accept answers along the lines of "... a set of tuples" or at a push, "... a table" (A table is a lay term for a relation, particularly when used in the context of SQL databases).  However, most times I receive an answer that starts something like "A relation is when you have another table with a foreign key...", at which point I ask "Are you talking about a relation or a relationship?", which is followed by stunned looks or muttered agreement.  I have interviewed hundreds of people over the years and only one or two haven't used a 'foreign key' based answer.

For some reason the concept of foreign keys in SQL databases have been confused with the relation.  I think it comes from the colloquial use of statements such as "Relate employee and employer on EmpNo" - the 'relate' really refers to a relationship but since the speaker may remember a single semester course in relational theory (apparently making him an expert) recalls that it sounds a lot like the 'relational' in relational database and thus the confusion starts.  Maybe it was the result of Bill Clinton's infamous statements where, I can imagine, during a brief period when mathematics was more practical than abstract, a group of exhausted mathematicians decreed "After much experimentation we can saefly say that 'sexual relations' are not part of the realtional model and probably refer more to the physical relationship between two somewhat consenting adults"

I'm no mathematician sitting in some old ivy covered building at an academic institution - I deliver systems based on SQL databases and (ADO) DataSets every day and am a big fan of the technologies that I use.  However, having had a background in more formal methodologies and working with great, intelligent people over the years - I have tried to understand the theoretical basis for what I use and a smattering of relational theory fits into that understanding - I think that some knowledge of relational theory is important to build systems on top of SQL Server.

With that as a background, hopefully you will understand why, when using ADO DataSets and Visual Studio, I cringe every time that I have to refer to the ADO version of 'relation'.  Even typing that last sentence makes my hair stand up. 

DataSets don't seem to officially claim to have anything to do with relational theory and with that as a disclaimer they don't do anything wrong.  Just as SQL Server or Oracle don't make any claims about fully supporting the relational model for fear of upset computer scientists and mathematicians spray-painting integrals all over the Microsoft campus.  However, since DataSets talk to SQL Databases which in turn are (sort of) based on the relational model - the distance between DataSets and relational theory is not that far - the inference that the DataSet relation has something to do with the relational model's relation does exist.   The only 'official' association that I have found is in MSDN (Datasets in Visual Studio Overview) which states "The structure of a DataSet is similar to that of a relational database; it exposes a hierarchical object model of tables, rows, columns, constraints, and relationships." - Which should be enough to upset a few theorists.

The ADO Relation is simply incorrectly named and propagates the confusion that people have about thinking about relations and relationship interchangeably.  The relation is a fundamental construct in relational theory and has formal relational algebra, relational calculus and other mathematics behind it.  The ADO relation is simply a badly named foreign key.  It is a fundamental error and is like calling the steering wheel of a car a chassis.

Not only does Microsoft abuse the term, they also use it inconsistently.  Visual Studio developers that have used the DataSet designer are used to the term 'Relation' as it is in the IDE (right click | Add | Relation) and I have myself said to developers things like "Create a relation (cringe) between those two DataTables".  However, the actual class that is being created is a DataRelation class.  Thankfully, the class is not called a relation and DataRelation is sufficiently devoid of significant meaning (like calling the aforementioned steering wheel a DirectionChassis) that one can get away with it.  But why then does Visual Studio call it a relation, and why couldn't they just have used 'relationship' in Visual Studio? 

Unfortunately it doesn't stop at Visual Studio.  The DataSet class has a property DataSet.Relations which returns, not a collection of DataTables as someone with some understanding of the relational model would expect, but rather a collection of DataRelations (er... foreign keys?).  DataSet.Relations.Add() does not add a new table, it adds a new DataRelation(ship).

To add to the confusion, the msdata schema definition (xmlns:msdata) uses the term 'Relationship' (msdata:Relationship annotation) or the xs:keyref annotation for foreign keys.  Generating DataSet Relations from XML Schema in MSDN recommends this after creating more confusion by stating "In a DataSet, you form an association between two or more columns by creating a parent-child relation." (aaargh! cringe! What on earth is a 'parent-child relation'?)

I think that Microsoft's abuse of the term 'relation' is shocking and breaks thirty-odd years of sound theory as well as breaking a few object orientation rules along the way by not naming things clearly and consistently.  I don't think that it is going to be an easy problem to fix, but the easiest change would be to rename 'Relation' to 'Relationship' in Visual Studio - most developers wouldn't even notice.  The DataRelation class is more core to the framework but is thankfully so badly named that it has no meaning anyway so it could almost be left alone.  I don't know how easy it will be to change the Relations property on the DataSet which is horribly orphaned and should have at least be named DataRelations from the beginning.

The number of people reading this post can never be as much as the number of developers going - Right click | Add | Relation - perpetuating the confusion.  I don't propose a Relational Vigilante Group that spray paints notations of set operators across the Microsoft campus and I imagine (sadly) that the generation that developed and believed in relational theory - the basis for nearly all our business systems - are literally a dying breed.  The father of relational theory EF Codd died in 2003 at the age of 79 and CJ Date, a driver of the relational model, is probably feeling a bit old and won't be able to compete with millions of young, energetic Visual Studio developers churning out thousands of blog pages every day.

Caveat Lector is is a Latin phrase meaning "Let the reader beware".  All that I ask is that as a .NET developer that you be aware of the terms 'Relation', 'Relationship' and their respective meanings in relational theory, ADO, visual studio and I suppose, the social sciences.

Simon Munro

kick it on DotNetKicks.com
8/17/2006 3:35:26 PM (South Africa Standard Time, UTC+02:00)  #    Disclaimer  |  Comments [0]  | 
Related Posts:
Is there value in Microsoft Certifications?
Peer out from under your rock - .NET 2.0 skills *are* required
Something for .Net Platform Developers to pay attention to...

Tracked by:
"KillChildren() - A sign of a bad programmer or a serial killer" (Delphi.co.za) [Trackback]
http://www.delphi.co.za/PermaLink,guid,52c318db-3fd0-4a1e-9ab4-502797d5c19b.aspx [Pingback]
"KillChildren() - A sign of a bad programmer or a serial killer" (The .NET Jobs ... [Trackback]
"phentermine diet pill" (phentermine diet pill) [Trackback]
"Funny Quotes" (Funny Quotes) [Trackback]
"pc memory upgrade" (pc memory upgrade) [Trackback]
"popcorn recipe ebook" (popcorn recipe ebook) [Trackback]
"generic cialis next day" (generic cialis next day) [Trackback]
"ital" (ital) [Trackback]
"foto scolaretta sex sex" (foto scolaretta sex sex) [Trackback]
"child custody" (child custody) [Trackback]
"crochet pillow edgings" (crochet pillow edgings) [Trackback]
"prom dresses" (prom dresses) [Trackback]
"invisibile ragazze inculate" (invisibile ragazze inculate) [Trackback]
"piu caldo fuoriclasse papa" (piu caldo fuoriclasse papa) [Trackback]
"museo santa giulia brescia" (museo santa giulia brescia) [Trackback]
"rubber stamping sites" (rubber stamping sites) [Trackback]
"dirty disney toons" (dirty disney toons) [Trackback]
"nokia 1110" (nokia 1110) [Trackback]
"Antivirus Software Reviews" (Antivirus Software Reviews) [Trackback]
"construction project checklist" (construction project checklist) [Trackback]
"chicago gay dating" (chicago gay dating) [Trackback]
"car seat covers dog" (car seat covers dog) [Trackback]
"cinema roma" (cinema roma) [Trackback]
"what is my computer hz" (what is my computer hz) [Trackback]
"babel" (babel) [Trackback]
"owner builder homes" (owner builder homes) [Trackback]
"SEIKO KINETIC SKH640" (SEIKO KINETIC SKH640) [Trackback]
"babysitter wanted fairbanks alaska" (babysitter wanted fairbanks alaska) [Trackback]
"foto spogliatoio" (foto spogliatoio) [Trackback]
"lilith" (lilith) [Trackback]
"si te vas mp3" (si te vas mp3) [Trackback]
"girls ugly" (girls ugly) [Trackback]
"Giochi di Luce" (Giochi di Luce) [Trackback]
"2002_06_24 - Departurebanish.com" (2002_06_24 - Departurebanish.com) [Trackback]
"1428_ministry - Calftryin.net" (1428_ministry - Calftryin.net) [Trackback]
"May Camp 2006" (May Camp 2006) [Trackback]
"Music" (Music) [Trackback]
"Toronto Wireless Community Network (TWCN)" (Toronto Wireless Community Network ... [Trackback]
"3337_backlash - Departurebanish.com" (3337_backlash - Departurebanish.com) [Trackback]
"Philip Morris agrees to buy Nabisco for $14.9 billion" (Philip Morris agrees to... [Trackback]
"main.htm" (main.htm) [Trackback]
"COMMISSIONERS’ CORNER" (COMMISSIONERS’ CORNER) [Trackback]
"Events" (Events) [Trackback]
"Mute_8977 - Calftryin.net" (Mute_8977 - Calftryin.net) [Trackback]
"Events" (Events) [Trackback]
"main.htm" (main.htm) [Trackback]
"Calftryin.net" (Calftryin.net) [Trackback]
"TIFFANY BOUDREAU PAX LODGE 2004" (TIFFANY BOUDREAU PAX LODGE 2004) [Trackback]
"Verreau_9420 - Calftryin.net" (Verreau_9420 - Calftryin.net) [Trackback]
"Mannequin Madness" (Mannequin Madness) [Trackback]
"2004_02_11 - Calftryin.net" (2004_02_11 - Calftryin.net) [Trackback]
"ALL ABOUT CANADA" (ALL ABOUT CANADA) [Trackback]
"NATURE HIKE" (NATURE HIKE) [Trackback]
"Gralty Automotive" (Gralty Automotive) [Trackback]
"May Camp 2006" (May Camp 2006) [Trackback]
"May Camp 2006" (May Camp 2006) [Trackback]
"Reel Views - Angie" (Reel Views - Angie) [Trackback]
"COMMISSIONERS’ CORNER" (COMMISSIONERS’ CORNER) [Trackback]
"SERVICE PROJECTS" (SERVICE PROJECTS) [Trackback]
"939_awards - Calftryin.net" (939_awards - Calftryin.net) [Trackback]
"Aluminum 2000" (Aluminum 2000) [Trackback]
"8266_opposition - Calftryin.net" (8266_opposition - Calftryin.net) [Trackback]
"Humanist - Calftryin.net" (Humanist - Calftryin.net) [Trackback]
"4029 - Calftryin.net" (4029 - Calftryin.net) [Trackback]
"The Camping Page" (The Camping Page) [Trackback]
"main.htm" (main.htm) [Trackback]
"3611_sixth - Calftryin.net" (3611_sixth - Calftryin.net) [Trackback]
"Thinking Day 2006" (Thinking Day 2006) [Trackback]
"IDEC" (IDEC) [Trackback]
"Murat - Calftryin.net" (Murat - Calftryin.net) [Trackback]
"Districts" (Districts) [Trackback]
"6070 - Calftryin.net" (6070 - Calftryin.net) [Trackback]
"Voluntary_2161 - Calftryin.net" (Voluntary_2161 - Calftryin.net) [Trackback]
"PREPARING FOR INSPECTION" (PREPARING FOR INSPECTION) [Trackback]
"Training" (Training) [Trackback]

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):