Home  >  Article  >  Database  >  The ability to uniquely identify a record in a database is called

The ability to uniquely identify a record in a database is called

(*-*)浩
(*-*)浩Original
2019-07-25 16:09:0815409browse

The primary key (primary key) is one or more fields in the table, and its value is used to uniquely identify a record in the table.

The ability to uniquely identify a record in a database is called

The key that uniquely identifies a record in the database is called a primary key. The primary key is a unique field in the database, which means that no two records in the data table can have the same primary key field. (Recommended learning: MySQL video tutorial)

In the relationship between two tables, the primary key is used to reference specific records from another table in one table. .

The primary key is a unique key that is part of the table definition. The primary key of a table can be composed of multiple keywords, and the columns of the primary key cannot contain null values.

The primary keyword is optional and can be defined in a CREATE TABLE or ALTER TABLE statement.

Function

1) Ensure the integrity of the entity;

2) Speed ​​up the operation of the database;

3) When a new record is added to the table, ACCESS will automatically check the primary key value of the new record and will not allow the value to be repeated with the primary key value of other records;

4) ACCESS automatically displays the table in the order of the primary key value record of. If no primary key is defined, the records in the table are displayed in the order in which they were entered.

Follow the principles

Principles that should be followed when establishing a primary key

1. The primary key should be meaningless to the user. If the user sees the data in a join table that represents a many-to-many relationship and complains that it is of no use, it proves that its primary key is well designed.

2. Never update the primary key. In fact, because the primary key has no other purpose except to uniquely identify a row, there is no reason to update it. If the primary key needs to be updated, the principle that the primary key should be meaningless to the user is violated.

Note: This principle does not apply to data that often needs to be sorted during data conversion or multiple database mergers.

3. The primary key should not contain dynamically changing data, such as timestamp, creation time column, modification time column, etc.

4. The primary key should be automatically generated by the computer. If a human intervenes in the creation of the primary key, it will have meaning other than uniquely identifying a row. Once this limit is crossed, there may be an incentive to artificially modify the primary key. In this way, the key means used by this system to link and manage record rows will fall into the hands of people who do not understand database design.

For more MySQL related technical articles, please visit the MySQL Tutorial column to learn!

The above is the detailed content of The ability to uniquely identify a record in a database is called. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn