Contents:
- Intro
- Basic Joins
- Inner Join
- Left Join
- Right Join
- Full Join
- Extra Joins
- Self Join
- Cross Join
- Natural Join
- Union
- Union All
- Intersect
- Except
- Semi Join
- Anti Join
- Set Theory
- Edge Cases
Primary & Foreign Key
Just a class has a roll number for every student, a table in SQL has a primary key for every row. Foreign key is your roll number in another table which contains your fee installments.
Primary key is a column in a table which has unique values to identify each row in that table for example your roll number is your class. Foreign key is a column in fees table which links roll number back to the class table.
In the FEES table, you probably have a different Primary Key for the payment itself (like Receipt_ID).
The Rule: In the
FEEStable, theReceipt_IDis the Primary Key (each receipt is unique), but theRoll_Numberis the Foreign Key (linking that receipt to a specific student).
“A Primary Key says: ‘This is me.’ A Foreign Key says: ‘This belongs to them.’“