The foreign key can be duplicated for the primary key

Source: Internet
Author: User

I only go to the primary key in the datasheet only, cannot repeat, but we often see the foreign key as a primary key, it can be repeated. The following figure

Employee Information table EMP, where empno and deptno as primary keys

EMP Table Structure

Department Table Dept

Here we can see clearly that there are a lot of repetitions in the deptno of the employee table EMP, and why Deptno can be duplicated as a primary key. The primary key is not unique. You can't repeat that.

This problem has been bothering me before, affecting my understanding of the primary key. There is no denying the primary key is unique, but when a table has two primary keys, at this time is the two primary key together as the primary key, that is, the Union key, two primary keys as long as there is a different, even if the difference. But when two primary keys are exactly the same, the error will be reported, the primary key can not be repeated.

The following table, Sid and ID as the primary key

at this point, although the SID is the same, but the ID is different, there is no error, but to change the ID of the second record to 1, the following error is reported: Primary key has duplicate duplicate

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.