What are primary keys and foreign keys?

Asked 20-Nov-2017
Viewed 748 times

1 Answer


0

Primary Keys
A table must have a primary key, to qualify as a relational table.
The primary key comprises of one or more columns whose data contained within is used to uniquely identify each row in the table. It can be thought of as an address. For e.g. the primary key would be the listing of street addresses, If the rows in a table were mailboxes.
When a primary key is composed of multiple columns, the data of every column is used to determine whether a row is unique or not.
To qualify for a primary key, a column must follow some points:
1. Already mentioned, the columns must be unique. To be clear, we’re referring to the data within the rows, not the column names themselves.
2. Also, no value in the columns can be blank or NULL.
When defining a table, you have to specify a primary key. A table must contain atleast one primary key, and its definition is mandatory.

Foreign Keys
A key that act as a primary key in another table is known as a foreign key. It is a set of one or more columns in a table. You needn’t to place to officially “designate” a foreign key as there isn’t any special code, configurations, or table definitions for it.
Hope you got the basic idea!!!