K
K
Karina2014-04-26 10:05:32
Database
Karina, 2014-04-26 10:05:32

Why is the primary key in a database a number and not a name?

The number (primary key) is usually given by sequence, so duplication is of course impossible. - Almost always in tables, p_id (int) is the primary key, and, say, mark_of_telephone (phone brand) is a simple field. Why is that? In theory, the brand of the phone should be the primary key.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dr_yand, 2014-04-26
@iKapex

It all depends on the architecture. Nobody bothers to make the brand of the phone the primary key.
But for example, you have a relationship of several tables, the Phone Brands table and the Phone Users table, where the phone brand will be a foreign key. So why duplicate the full name of the phone brand there, if you can write down a shorter numerical value.

S
svd71, 2014-04-26
@svd71

the primary key can include any type (alphabetic - only up to 128 characters or 256 - depends on the organization in the DBMS. if the field is larger, then the remaining characters are not taken into account when creating the key). Also, the key may include not one field, but several and with different types. But the highest speed of work is with integer type keys. Some DBMSs specifically optimize the code for processing keys with such types in order to achieve the highest speed of working with such surrogate keys.
In addition, with a complex composite key of several fields, some redundancy of the base is obtained in that all values ​​of these keys must be stored in referencing tables and more complex queries must be made when selecting and processing data.

K
killla, 2014-04-26
@killla

The primary key only performs the function of uniqueness. Provides unique identification, non-repeatability.
This is the minimum set of fields by which a row can be identified.
If there is confidence that the brand of the phone never repeats, then the ID column can be thrown out of the table altogether.
If the stamps are repeated, then an ID column is added to enable the row to be uniquely identified. It makes no sense to make a composite primary key from two fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question