Tuesday, July 15, 2008

Pet peeve pluaral database table names

I was reading this post and the post it links to as it started to come to why plural table names drive me crazy. I have a pet peeve about database schemas. I guess this is a sign I am getting old (mature developer). Way back in the dark ages we described our data structures (schema) in a specific way. I guess in the old days we defined our data structures in C like so:

struct example {
int x;
int y;
};

Then as we learned about objects C++, Java, Objective-c we started adding functions (methods)
to our data structures.

class Example {
public:
Cube();
~Cube();
int add();
int x;
int y;
};

However the data schema was still singular. And so when ever I would see a table schema:

CREATE TABLE examples (INT x, INT y);

I associated with an MS Access database schema got upgraded to a RDBMS. The individual who created the database probably never had formal data structure education. So usually the schema had little if any normalization to it and generally I would need to migrate the entire database schema at some point. Fortunately for me I would see this more and more because novice tools such as PHP and ASP where allowing more novice computer users to create web applications using RDBMS (DBMS as mysql was at the time). This was a wonderful thing more application online means I am more in demand! WOOT! However I still keep seeing this more frequently and more frequently. And now that I am doing more work with Rails I am starting to wonder why are all these table names plural? From the main rails site under documentation the first tutorial I am seeing a possible answer.

Plural table names I guess are all the rage. Do they teach this in data structure classes? I mean should I expect to see classes in Ruby:

class Examples < ActiveRecord::Base
# Uh what?
end

None of the examples show that ... so why do they define the relation schema plural? Well I am sure my Python peeps are old school like me and sqlalchemy wouldn't do that... DOH! Even sqlalchemy Python "et tu Burte"?

Guess I am just dated. In the days of ORMs it maybe make more sense to use plural because we only references myobject.examples.query(foo). And since ORM schema is autogenerated then developers are not writing "Database Schemas" any more so defining the data is just whatever is generated by the ORM.

2 comments:

  1. It makes sense to me. Taking your examples database table, what is defined in each row of that table? An example. The table is what? A collection of examples.

    It makes perfect sense that the table, the collection, would be plural, while the class object would be singular.

    As billy joel once said "The good old days weren't always good, and tomorrow ain't as bad as it seems"
    ReplyDelete
  2. If you look at it as what FROM really is querying data that is define with the schema of 'example'. FROM table that has definition 'example':
    SELECT * FROM_DATA_DEFINITION example;

    Alas this is more from a data definition perspective and most developers look at it form an ORM these days.
    ReplyDelete