MySQL + SQL · Lesson 1

Primary Key Vs Foreign Key

अंतर

FeaturePrimary KeyForeign Key
उद्देश्यRow को unique पहचाननादूसरी table से link
NULL allowed?नहींहाँ
Duplicates?नहींहाँ
Table में कितनीएककई
Auto indexहाँIndex सुझाया जाता है

एक Example में दोनों

students(roll_no PK, name)
fees(fee_id PK, roll_no FK -> students.roll_no, amount)
roll_no, students में PRIMARY और fees में FOREIGN है।

सारांश

  • एक ही column एक table में primary key और दूसरी में foreign key हो सकता है।
  • PK: unique व not null; FK: link व repeat/null हो सकती।
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।