MYSQL - 什么是主键? [英] MYSQL - What is a primary key?
问题描述
我正在学习Mysql,我正在创建数据库.所以,看了几个网站后,主键的定义是:
I'm in the process of learning Mysql, and I'm creating databases. So, after looking at several websites, the definition for a primary key is:
PRIMARY KEY 约束唯一标识数据库表中的每条记录.
The PRIMARY KEY constraint uniquely identifies each record in a database table.
并像这样使用:
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
PRIMARY KEY (P_Id) //primary key is on this line
)
然而,我仍然不知道它的用途以及我们为什么需要它.所以我的问题是.
However, I still don't know what it's used for and why we need it. So my question is.
有人可以向我解释什么是主键(基本英语)以及我们为什么需要一个主键以及它的用途是什么?
Can someone explain to me what a primary key is (in basic english) and why we need one and what is it used for?
谢谢.
推荐答案
A primary key is a column that is defined as uniquely identifying each row in a table.
此外,通过将列定义为 PRIMARY KEY
,它可以被引用为 外键 定义参照完整性a> 约束.
Also, by defining a column as PRIMARY KEY
, it may be referenced as a foreign key in other tables when defining referential integrity constraints.
这篇关于MYSQL - 什么是主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!