https://vimeo.com/318455676 We just saw that more than one set of attributes can be a key. But in a database, we want to agree on just one of them, once and for all. We, therefore, need to designate a primary key! Note that every key is considered a candidate key. For an attribute to be considered a candidate key, it must fit the criteria established in the previous chapter. Criteria for choosing a primary keyIn the context of relational databases, the notion of the primary key is very important. In fact, some relational database management systems (RDBMS) will not allow you to create a table without assigning a primary key! The selection of the primary key can actually be arbitrary. However, you will want to take into account the following criteria:
Yes, but what if none of the candidate keys seem simple or have a reasonable number of attributes? Good question. In that case, you can create an artificial key. Use an artificial keyAn artificial key is an attribute that is added to the relation. This attribute has no real meaning in the domain being modeled; its sole purpose is to uniquely identify the tuples of the relation. Remember our apple relation? Apple
In the domain being modeled (apples), weight, diameter, and color satisfactorily describe one aspect of our apple (here, it's its form). However, the identifier column does not inherently describe the apple; in fact, we could very well have switched identifiers, and assigned the identifier As you have guessed, this means that the identifier attribute is an artificial key, because it was created solely to differentiate and identify the apples! Whether you choose to use an artificial key or not, there is an important point to bear in mind: Key attributes can never be For any other attribute value, however, it is possible to have a cell with an unknown or non-existent value. In this case, it is possible to specify its value as Represent a primary keyThe attributes of a primary key are usually indicated by the notation [PK] (for Primary Key) placed after their names.
Another way of specifying these attributes is to bold them:
Go Further: Why Are Artificial Keys So Popular with Databases?Artificial keys are generally quite common in databases. In some applications, they are even used systematically. Why?
Summary
|