Is it considered good practice to use several PRIMARY KEY in one table?
-
Is it good practice to use a few PRIMARY KEY in one table?
Let's say:
create table ConsPravo ( id_ int (100) NOT NULL AUTO_INCREMENT, position varchar(2500) NOT NULL DEFAULT '0', question varchar(2500) NOT NULL DEFAULT '0', PRIMARY KEY (position) PRIMARY KEY (question) PRIMARY KEY (id_) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=cp1251;
-
No, some primary keys. not Good practice. The main purpose of the primary key is to uniquely identify the substance of the table.
The primary key must be so that during the life of the recording, if possible, never change. In some cases, there is a certain indication of the primary key. For example, bi-box country codes (c)
RU
these codes are standardized, applied equally throughout the world, changed only with geopolitical changes, that is, the key changes when the essence changes. In establishing a country directory, such a field can be made a primary key. In cases where there is no relevant characteristic sign, only a number of IDs are made.Long text fields are very bad primary keys because they can easily have banal seals. An attempt to correct such a seal would lead to the need to change the field not only in this table, but also in all tables referring to it. And such records could be millions... In addition, policy itself
FOREIGN KEY
It won't just change the primary key if there are references. The base cannot allow the sub-sheets to have records of the reference fields of the missing in the head table. Consequently, before a change in the primary key is made, references to the new key should be made in all the sub-sheets in advance, but the new key should already exist in the table. The only way of such a change that does not violate the reference is to create a new recording of the new key, to correct all references and to remove the recording of the old key.Creating references to different fields of the same record not Good practice. There is no point in referring to the same substance in different ways, much easier in all bases to refer to the same thing. The values of the other fields of this nature can always be found on its only primary key.