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:
The PRIMARY KEY constraint uniquely identifies each record in a database table.
and is used like this:
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?
Thank-you.
A primary key is a column that is defined as uniquely identifying each row in a table.
Also, by defining a column as PRIMARY KEY
, it may be referenced as a foreign key in other tables when defining referential integrity constraints.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With