What is a primary key and a foreign key?

Source: Internet
Author: User
Tags arabic numbers
Document directory
  • What is a primary key and a foreign key?
What is a primary key? What is a foreign key? [Tag: foreign key, key, foreign key] What is a primary key in a database? What is a foreign key? What are their functions. Please give me the answer as much as you can !! ☆Snow silent ☆answer: 3 popularity: 6 solution time:

Satisfactory answer

Favorable rating:100%

To put it bluntly
Let's talk about the primary key: one or more columns of a table (Link) can be used as the primary key, provided that this column is used as the primary key, this column ensures that the values of individual rows (tuples) in this column cannot be the same. For example, if you use the name attribute as the primary key, this primary key is not necessarily acceptable, if two people have the same name, the values of the data in the tuples under this attribute cannot be different. It is a good choice to use Arabic numbers as the primary key.
Foreign key: A table (relational) Column (attribute) exists in both table 1 and table 2. It is not the primary key of table 1, it is the primary key of table 2. It can be said that it is the foreign key of table 1.
So what is the candidate key? A column (attribute) that uniquely identifies a row (tuples) in a table (Link) is called a candidate key, it is also called a candidate keyword or candidate code. From this point of view, there can be more than one candidate key. We can also see that the primary key is also a candidate key.

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.