Database Reference
In-Depth Information
Primary Keys
Every row in a table should have some column (or set of columns) that
uniquely identifies it. A table containing customers might use a customer num-
ber column for this purpose, whereas a table containing orders might use the
order ID. An employee list table might use an employee ID or the employee
Social Security number column.
New Term
Primary key A column (or set of columns) whose values uniquely identify every row in
a table.
This column (or set of columns) that uniquely identifies each row in a table
is called a primary key . The primary key is used to refer to a specific row.
Without a primary key, updating or deleting specific rows in a table becomes
difficult because there is no guaranteed safe way to refer to just the rows to be
affected.
Tip
Always Define Primary Keys Although primary keys are not actually required, most
database designers ensure that every table they create has a primary key so future data
manipulation is possible and manageable. In fact, if you omit the primary key, some
database engines create one automatically for you, and the odds of it being what you'd
have wanted are pretty slim. Bottom line, always define primary keys!
Any column in a table can be established as the primary key, as long as it meets
the following conditions:
No two rows can have the same primary key value.
Every row must have a primary key value (primary key columns may
not contain NULL values).
Tip
Primary Key Rules The rules listed here are enforced by MariaDB itself.
Primary keys are usually defined on a single column within a table. But this
is not required, and multiple columns may be used together as a primary key.
When multiple columns are used, the rules previously listed must apply to all
columns that make up the primary key, and the values of all columns together
must be unique (individual columns need not have unique values).
 
 
Search WWH ::




Custom Search