About primary keys and auto increment columnsIdeally, every table should have a Primary Key. It's very important that a table has a Primary Key. There are two good reasons why a table should have a Primary Key. First, a Primary Key uniquely identifies each record in a table so it helps to ensure against redundant data in that table. This also means that we can "point" to a specific record in the table. Second, it is also the instrument used to establish a relationship between tables. This will be of importance when you want to retrieve data from multiple tables in a query.
Some guidelines for establishing a Primary Key:
- Itís value must be unique.
- It can never be null.
- It must directly identify each value of the remaining fields in a given record of a table.
- It should comprise the minimum number of fields to guarantee uniqueness.
A Primary Key may consist of multiple fields.
A lot of database developers add an identity or auto column to each of their tables to ensure uniqueness. This may sound like a good idea but, if the rows in a table are naturally unique, then the use of an identity column is not recommended and not needed. Using an (unnecessairy) auto increment or identity column can reduce the performance of your database because it may require the use of extra joins, which requires more I/O to read your table. Advantages of using identity columns are:
- Uniqueness is always guaranteed.
- This is a simple and flexible implementation.
- DeZign for Databases: Learn more about DeZign for Databases.
- Getting started with DeZign for Databases: Start making a data model directly.
- Display data types in a diagram: Learn how to display data type and/or domain info in the entity boxes on your diagram.
- Build your next data model with DeZign for Databases trial software, available for download directly from Datanamic's download section.