..
When designing a database to support applications is essential to consider how to handle primary keys. There are in this regard at least two schools of thought: one that argues that the right thing to do is to use the so-called surrogate keys (ie not based on real data) and another that claims that must be used instead of real data as key values. Then there is a middle path which consists in 'a database for use within both of these solutions, depending on the relative pros and cons (which we will soon).
When designing a table it usually contains one or more columns that make up its primary key. As we know a table's primary key is a value (or a combination of values) that uniquely identifies each row. As mentioned previously, if a key is made up of real values is called natural key, but if for example the key is generated every time you insert a row in the table it is called surrogate key. A surrogate key is usually a numeric value in SQL Server, and often the columns of this type are those of identity, of which more later.
A natural key is made up of real data, ie data that have a relationship with values in other columns of the row (eg the tax code of an individual in a Customers table that also contains its generality). Even a surrogate key uniquely identifies a row in a table but its value has no relation to other values of the line and it is simply generated and stored.
We analyze the pros and cons of the two types of keys beginning with the surrogate:
The PRO
AGAINST THE
As for the natural keys:
The PRO
AGAINST THE
| |
MS Access (Advanced)
Learn how to create and manage databases quickly and easily. Starting from 29 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
SQL and Database (Course)
Create and manage relational databases. From 39 €. |