Why you shouldn’t use a date field as a primary key

There was a debate between the developers today talking about why you should use waits in your code.

A wait is where you get the code to wait for a period of time before the code continues.

The reason you might do this is if you created a primary key using a date field.  When you try to insert a lot of rows into the database the primary key will be the same because a computer can insert more than one record per millisecond.

So sometimes seeing a wait in the code could be a sign of problems ahead and you could find the primary key is a date.

To avoid potential problems with primary keys it’s better to use an Int or some kind of simple sequential counter.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s