Primary Key:
The unique identifier for a row of data in a table is the primary key. This can be a single column or a combination of more than one column, in which case it is known as composite key.
Secondary or Foreign Key:
A key column in a table that identifies records in a different table is called a secondary or foreign key.
Example:
Let us say that you have an ‘order’ table and an ‘item’ table. In the ‘item’ table, let us say that your primary key is the combination of ‘order_id’ and ‘item_number’. In this case, the ‘order_id’ which is the primary key of the ‘order’ table is a foreign key in the ‘item’ table.
No comments:
Post a Comment