MySQL + SQL · Lesson 1
Primary Key Vs Foreign Key
अंतर
| Feature | Primary Key | Foreign 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 हो सकती।