Data Science Interview Preparation

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.
'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Theme images by Barcin. Powered by Blogger.