Primary Key vs Foreign Keys in SQL
Identify difference between Primary Key and Foreign Keys in SQL.
Explanation:
Primary Key: Column with unique values, No Null values. Only one Primary Key is allowed in a table. It's value can not be deleted (from parent table)
Foreign Keys: A column ( or columns ) that reference a column (most often the primary key) of another table. More than one foreign key are allowed in a table. Null values are allowed. it's values can be deleted from child table
Example:
Table 1: Students (Parent table) with Primary Key - Student ID
Table 2: Enrollments (child table) with Foreign Keys - ( Student ID, Class ID)
Table 3: Classes with Primary Key - Class ID
Image Source : Google image
© Copyright 2022, crackdatascienceinterview.in. All rights reserved.