Lec-9: What is Primary Key in DBMS | Primary Key with Examples in Hindi
What is a Primary Key in DBMS?
Introduction to Keys in Database Management Systems
- The concept of keys is crucial in Database Management Systems (DBMS), relevant for competitive exams, college/university assessments, and job placements.
- This video focuses specifically on the primary key, emphasizing its importance across various database operations including normalization and SQL.
Understanding the Primary Key with an Example
- To illustrate the primary key's role, an example involving 100 students is presented. Data such as registration number, roll number, names, age, gender, and contact details are stored in a table format.
- The need for unique identification arises when managing student data; hence the concept of a "key" becomes essential.
Defining Keys: Unique Identification
- A key functions similarly to a physical lock and key system—each lock has a unique key that opens it. In databases, this means uniquely identifying records.
- Unlike common attributes like names or ages which may not be unique among students, keys must ensure distinctiveness to avoid confusion.
Candidate Keys: Attributes with Unique Values
- Attributes such as phone numbers or Aadhaar card numbers serve as candidate keys because they are expected to have unique values across different entries.
- Other examples include registration numbers or roll numbers assigned by educational institutions that guarantee uniqueness.
Limitations of Candidate Keys
- While candidate keys are unique identifiers, their reliability can be compromised if students do not provide accurate information (e.g., incorrect phone numbers).
- There’s also the possibility of siblings sharing the same phone number or other attributes leading to potential duplication issues within the database.
Null Values and Their Implications
- Not all students may provide certain information (like phone numbers), resulting in null values that complicate data retrieval processes.
Understanding Primary Keys in Databases
The Importance of Unique Identification
- Each entry in a database must be uniquely identifiable; multiple entries for a single student indicate a lack of uniqueness.
- A field cannot be left empty (not null); it must contain valid data, such as a phone number or identification number.
Handling Null Values
- If a required field is not filled correctly, it leads to incorrect database entries. For example, entering invalid characters just to avoid leaving the field empty is problematic.
- Institutions may require mandatory fields like Aadhaar card numbers for admission; failure to provide these can result in denial of admission.
Defining Primary Keys
- A primary key must be both unique and not null, ensuring that each record can be distinctly identified without any duplicates.
- In smaller colleges, roll numbers may serve as primary keys, while larger institutions might use registration numbers due to their uniqueness.
Generation and Assignment of Primary Keys
- Users do not choose their primary keys; they are assigned automatically by the institution (e.g., registration or roll numbers).
- Similar processes occur at passport offices where passport numbers are generated and assigned as unique identifiers.
Constraints on Primary Keys
- Both uniqueness and non-null constraints make defining primary keys challenging; they cannot have duplicate values or remain empty.
- While candidate keys can exist without being mandatory (can be null), only one primary key is allowed per table due to its strict requirements.
Candidate Keys vs. Primary Keys
- Multiple candidate keys can exist within a database, but only one can be designated as the primary key because it fulfills both uniqueness and non-null criteria.