Ever wondered why we do not use numeric fields as primary key ?
Each one of us might be familiar that when we create a ‘Department’ table we surely create a column named ‘DeptId’ which will end up as our primary key column. Have you ever wondered why we did not make the ‘DeptName’ column as the primary key? Why not? Even ‘DeptName’ column is supposed to have unique entries!!
I am going to give you two reasons to support the title of this article. They are as follows:
1.Performance of course
The database engine is much faster when it has to do sorting and searching of numbers. When you are dealing with strings alphabetic arrangement and sorting takes way more time which in turn would decrease the performance of the application that you are working on. You can see the difference when you specifically do lots of joins with the tables that have primary key.
2. Names of departments can change
If you need to rely on the ID value being stable in time, creating an artificial key (in the form of an additional ID column) solves the problem because it’s unlikely you’ll ever need to change the ID.