Must there be a primary key for each table in SQL?

Source: Internet
Author: User

The role of the primary key: 1) To ensure the integrity of the entity; 2) speed up the operation of the database 3) when you add a new record to a table, the database automatically checks the primary key value of the new record and does not allow the value to repeat with the primary key values of other records. 4) The database automatically displays the records in the table in the order of the primary key values. If no primary key is defined, records in the table are displayed in the order in which they are entered.

The primary key is not to be unavailable, and can be from:

1. Whether the business requirements are met

2. Data query efficiency (primary key can improve query efficiency, of course, reasonable index substitution can also)

These two angles weigh whether a primary key is required.






This depends on the function of the table. Use to store a large amount of data, and need to query frequently, the establishment of primary key can speed up the query efficiency and reduce the burden on the server. In the absence of this requirement, the establishment consumes more server resources instead.

Setting does not set the primary key to see business or demand
If you are simply working on a single table, it is not necessary.
There is no effect on any table operations that are not associated with multiple sheets.
The primary key is simply an association between a table and a table, and there is an automatic addition of indexes when the primary key is being built, and in some cases it can increase the query speed.

Must there be a primary key for each table in SQL?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.