Nicko think on software, web, ideas

September 4, 2007

Readable Primary Key

Filed under: think&think — Nicko Satria Utama @ 11:15 am

Most of the database designer, programmers or system analyst knows the importance of primary key. It gives the row unique identify so there is no 2 or more rows in the table has the same value in those column.

Some programmers make the primary key only a sequence of number like 1 to maximum number in the PK column using auto increment from the database itself or auto increment from the code. It is good since the database will handle the uniqueness; but it will loose the meaning of the data.

The other reason data will grow fast so the auto increment will loose its functionality.

for example:

PK using integer datatype and auto increment. If the data will grow more than 4 billion records, The programmer or database developer will change to higher datatype like long integer. It is not easy to convert lowest datatype to higher datatype since some RDBMS need recreate the tables and refill again.

PK using string datatype with specific format and length. We can easily predict the data and its growth. With the format of the PK I can easily read the meaning; like 20070112Axx; the record was built on 12 January 2007. It is easy to convert since it is just a string.

Advertisement

1 Comment »

  1. Yes, it’s right. RDBMS will create new table and fill it.
    But, using string as key is slower than int or long int, when we doing searching using it.

    Comment by Ishak — January 14, 2008 @ 7:37 pm


RSS feed for comments on this post. TrackBack URI

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 )

Connecting to %s

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.