Tuesday, September 14, 2010

nuBuilder Primary Keys

Some have wondered why nuBuilder uses the Primary Key method it does (using php's uniqid() to create a string) and not Automatically Incremented Integers.

Here are some reasons:

  • If you rely on the database to tell you what the ID is going to be, you can never populate foreign keys on a child table without first creating the parent record. (generally that won't matter, but Murphy's Law will come up with a time when it does)
  • It is hard to create a table like contacts from two tables like employee and customer. Because both are likely to have the same Primary Keys (both probably have Primay Keys 1 and 2)
  • Creating a Primary Key from two other Primary Keys is harder with numbers. (123 and 45 gives the same result as 12 and 345)
  • When you use AutoIDs you need to go back to the database to get an answer you could have otherwise given it.
Essentially the more you automate a database, the less control a programmer has over it.

1 comment:

Murz said...

I use nuBuilder to do actions on already created database, so at now it have int and auto_increment primary keys and it is too hard to change this, because other applications work with this database too.

Will be good if nuBuilder have the option what type of primary key use in table.

And how I can operate on tables with more than one columns in primary key?