Lec-9: What is Primary Key in DBMS | Primary Key with Examples in Hindi
Summary
TLDRThis video from the Gate Smashers dives into the concept of primary keys in database management systems (DBMS). It explains the importance of keys in various exams and scenarios, including competitive exams and placements. The video uses the analogy of a lock and key to illustrate the uniqueness of primary keys in identifying database entries. It discusses candidate keys, their properties of being unique but potentially nullable, and contrasts them with primary keys, which are not only unique but also non-nullable and are assigned by the system. The video clarifies that a database can have only one primary key, emphasizing its critical role in ensuring data integrity and uniqueness.
Takeaways
- 🔑 The primary key in a database is a unique identifier for each record, ensuring that no two entries are the same.
- 📚 The concept of keys, including primary keys, is crucial in database management systems (DBMS) and is frequently tested in exams and interviews.
- 📝 Candidate keys are attributes that can uniquely identify a record, but they may allow for null values and are not necessarily unique across all records.
- 🚫 Primary keys must be unique and not null, meaning every record must have a value for the primary key, and no two records can share the same primary key value.
- 👨🎓 Examples of primary keys in educational settings include student registration numbers and roll numbers, which are assigned by the institution and cannot be chosen by the student.
- 🏢 In professional contexts, identifiers like passport numbers, Aadhaar card numbers, and license numbers serve as primary keys because they are issued by authorities and are both unique and mandatory.
- 🚫 It is not possible to have more than one primary key in a database because the primary key's role is to uniquely identify each record, and this cannot be achieved with multiple attributes.
- 🔍 The selection of a primary key depends on the context and the attributes available in the database, with factors like uniqueness and the necessity of having a value being key considerations.
- 🛠️ The primary key is a fundamental aspect of database normalization and is used to enforce data integrity and support relationships between tables.
- ❌ Attempting to assign a primary key that allows for null values or duplicates would lead to data anomalies and is not permitted in well-designed databases.
Q & A
What is the primary key in the context of a database?
-The primary key is a unique identifier for each record in a database table, ensuring that each entry can be distinctly recognized and that no two records have the same key value.
Why is the concept of keys important in DBMS?
-The concept of keys is crucial in DBMS because it helps in uniquely identifying records, ensuring data integrity, and is fundamental in database operations such as normalization and querying.
What is the difference between a primary key and a candidate key?
-A candidate key is any column or set of columns that can uniquely identify a row in a table, while a primary key is the chosen candidate key that is used to uniquely identify each record in a table.
Can a table have more than one primary key?
-No, a table cannot have more than one primary key because the primary key must uniquely identify each record, and having multiple would violate this uniqueness constraint.
What is the significance of the primary key being 'not null'?
-The primary key being 'not null' ensures that every record in the database must have a value for the primary key, preventing the creation of records without an identifier.
Why is the primary key not chosen from user input?
-The primary key is not chosen from user input because it needs to be unique and not null for every record. It is typically generated automatically by the system to maintain these constraints.
How does the concept of a primary key apply to real-world examples like student registration numbers or passport numbers?
-In real-world examples, unique identifiers like student registration numbers or passport numbers serve as primary keys, ensuring that each individual's information is uniquely identifiable and distinct.
What happens if a candidate key is not unique or can be null?
-If a candidate key is not unique or can be null, it cannot serve as a primary key because the primary key must guarantee both uniqueness and the presence of a value for every record.
Why are attributes like name, age, or date of birth not suitable as primary keys?
-Attributes like name, age, or date of birth are not suitable as primary keys because they can have duplicate values, which violates the uniqueness requirement of a primary key.
How does the database ensure that the primary key remains unique and not null?
-The database ensures the primary key remains unique and not null through constraints and system-generated values, preventing the insertion of duplicate or null values for the primary key.
Outlines
🔑 Introduction to Primary Keys
The video begins by emphasizing the importance of the concept of keys in database management systems (DBMS), particularly the primary key. The speaker uses the analogy of a physical key and lock to explain the uniqueness of primary keys in identifying records in a database. The discussion then shifts to the practical example of managing student records, highlighting the need for a unique identifier like a registration or roll number. The concept of candidate keys is introduced as potential unique identifiers, but the primary key is distinguished by its necessity and non-optional nature.
📚 Attributes of Primary Keys
This section delves deeper into the attributes that make a primary key. The speaker explains that while candidate keys can be unique, a primary key must also be non-nullable, meaning it cannot be left empty. Examples such as phone numbers and Aadhaar cards are discussed, noting that while they are unique, they might not be provided by every student, thus not fulfilling the non-nullable requirement. The speaker then contrasts this with registration or roll numbers, which are both unique and non-nullable, making them ideal for primary keys. The video also touches on the idea that primary keys are assigned by the system and not chosen by the users.
🚫 Limitations on Primary Keys
The final paragraph addresses the limitations regarding the number of primary keys in a database. The speaker makes it clear that a database can only have one primary key due to the stringent requirements of uniqueness and non-nullability. The analogy of hiring multiple people for a single job to illustrate the redundancy of having multiple primary keys is used. The speaker also mentions that while there can be multiple candidate keys, only one can be designated as the primary key, which is determined by the specific context and requirements of the database. The video concludes with a reiteration of the primary key's defining characteristics: it must be unique and not null.
Mindmap
Keywords
💡Primary Key
💡Candidate Key
💡Unique
💡Not Null
💡Database
💡DBMS
💡Normalization
💡Attributes
💡Registration Number
💡Roll Number
Highlights
The primary key in DBMS is crucial for uniquely identifying records.
Concepts of keys are frequently tested in competitive exams and academic assessments.
A primary key is essential in database normalization and SQL.
The primary key concept is introduced with an example of managing student records.
A key's uniqueness is compared to a lock and key mechanism.
Not all attributes like name or date of birth can guarantee uniqueness.
Attributes like phone number, Aadhaar card number, and roll number are typically unique.
Candidate keys are attributes that are unique but may allow null values.
Primary keys are selected from candidate keys based on their appropriateness and non-nullable nature.
Primary keys must be unique and not null, ensuring accurate identification of records.
The value of the primary key is assigned by the database, not provided by the user.
A database can only have one primary key, ensuring singularity in record identification.
The selection of a primary key depends on the specific requirements of the database scenario.
Examples of primary keys include registration numbers, roll numbers, Aadhaar card numbers, and passport numbers.
The primary key is a critical component in database design and management.
Transcripts
Hello friends, welcome to the Gate Smashers
We're going to discuss in this video.
What's this primary key?
In DBMS, key's concept is most important.
Whether you talk about competitive exams.
Whether you talk about college
or university level exams
Or even talk about placements,
there also Concept of keys are
Certainly asked.
And that doesn't means that only one key,
like what is primary key?
what is candidate key?
That's enough, No.
If you talk about the normalization.
Talk about the sequel,
The concept of keys will be used everywhere.
So in this video, I'm just focusing
On the primary key.
So What is the story of primary key?
What is it, how do we talk?
So I'm starting this story with a simple example
Let say, we have 100 students in a class
Now I have to store the data of 100 students.
Now I will obviously not always
call 100 students by face.
If I have to take an attendance. There is an online system.
So what would I do in the online system?
I will save the details of all those students
I'll make Excel file.
In which I have registered the student's
registration number, roll number,
Father's name, mother's name,
student's name, age, gender, marks
Adderes, phone number, aadhaar card,
make multiple value, multiple attributes.
I'll make a table.
Within which multiple attributes Will define.
Then we will fill the details
of all the students.
In a way you can visualise,
there is a table in which we have done
all the entries.
Now here comes the concept of key,
first of all, what is the meaning of key?
Like we have key in the lock.
What is its property,
that every lock has its unique key
That key will open only that lock.
I'm talking about the best case,
I'm not talking about the normal case.
A lot can happen in India.
Maybe you can open multiple locks with the same key,
but I'm not talking about that.
Not even I am talking about the master key
who is roaming around with thieves.
What is the normal key's concept
that there is only a key for a lock.
From that, I can only open that lock,
so the same thing we are doing here.
Means you are uniquely identifying something.
If two things are the same,
So identify them that you are different
and you are different
How will you do? From the key.
Now here's talking about the database,
then in the database, How we will do?
You have attributes in the database.
Now If I say name
If we take the student's name,
then is the student's name guaranteed
That will be different?
No, you check yourself,
you will have a lot of kids in your class,
in college, university
Whose name, even if you see
the first name last name, will be same.
You can't take guarantee.
Age, date of birth,
there are 365 days in 1 year.
Or if in leap year 366 days, then obviously
somewhere the date of birth will be same.
Here if we talk,
father's name can also be the same,
mother's name can also be same.
In case, If two brothers and sisters
or two brothers are studying together,
obviously their father mother will be same
Similarly, the multiple attributes may have same values,
but which are the attributes
cannot have same value?
That will be Unique key.
Which could be?
Let say, your phone number,
It will comes in your mind that sir,
The phone number will be different.
Fine. The phone number will be always different.
The Aadhaar card number.
Yes, you can say that the adhar card we have,
Everyone's numbers will be different.
Pan card also, although
I am talking about the students.
So In the case of student,
even if you do not take the PAN card, even if you take it,
then also it will be unique
In this way, even if you take the license number,
it will be unique
Take Registration number, Or roll number
Because in many universities,
there are registration numbers.
In many colleges, Roll numbers are there,
then it will also be unique.
So in this way,
you can count the multiple attributes somewhere that,
sir all these will be unique.
There are no duplicacy in it.
Now let's talk about,
what we all these attributes.
We call all these attributes, Candidate key
What are all these attributes being made?
All of these are candidate keys.
So what are the property of the candidate keys?
It is unique.
So Unique I Achieved
But will unique alone work?
Can't work, how?
Let suppose, the phone number
I'm assuming the phone number,
If i want to find out a student
then I'll fill in the phone number
and the details will come.
So, is there any guarantee that
every student must have given the correct phone number
or even given the phone number?
This is also not guaranteed
and there is also a possibility that,
let suppose if two brothers and sisters are studying together,
then both of them may have given
the same number in the database.
That's possible, isn't it?
This case is possible.
You can say that the student does not
given the phone number.
Or it is also possible that
if there are two siblings,
then somewhere they mentioned the same phone number.
The two of them does not have different Phone Numbers.
Next say, Aadhaar card.
Now you can also say that it is not
necessary that every single student has applied.
If a student has applied,
then obviously their Aadhaar card will be unique.
But what is the guarantee
that if we talk about your college or university,
let suppose if there are , 10,000-20,000 students
or 50,000 students.
Can you give the guarantee that all
students will have Aadhaar card?
All students will have PAN card,
license number.
That is not a guarantee.
And because of this, it can happen that
if I am looking for a student,
means if i entered his entry online,
then there are two or three entries corresponding to it
or no entries corresponding to it.
Because you didn't have that in your database,
So what is the second property that you have here?
That's Null.
It could also be possible
that I had not given the phone number.
I took admission in the university,
in any college,
He asked the phone number,
I didn't give it there yet
or gave a wrong number.
So obviously somewhere I put this field,
let suppose keep it null,
Or with the same sibling case,
if you give same phone number,
it will pick the same phone number
and what will happen because of it?
Tomorrow when you will find the student,
then there will not be one entry corresponding to it,
there may be two or three entries.
So it is not uniquely identified.
So the concept of the database is that
I can uniquely identify each one.
I can uniquely identify every single tuple ,
it will not be achieved,
then when it will be achieve,
that one it should be unique.
Second it should not be null,
Not null mean that
you can't leave this field empty.
you can't leave this field empty,
You have to fill something in this field,
Something has to be filled.
Let suppose if I talk about the phone number
or the Aadhaar card, the PAN card.
So, let suppose, a student came to you
get admission in your college.
You'll definetly fill that field.
Now if you fill that field.
If Students say that I don't have
an Aadhaar card number yet.
So what will you do?
Whether you fill any wrong value in that field? like $, #
Just to fill it.
Because you can't leave empty,
It's a not null field,
then what will happen, in that case,
you are making the wrong entry in the database.
What could be the second case?
You will say, want to take admission,
give me the aadhaar card number
because aadhaar card number will have to be filled,
it's a not null field.
Null means empty, you can't leave null,
what will you do then?
You will say, you will not get admission now.
Bring the Aadhaar card number first.
So obviously, this case will not happen,
then obviously other competitors
college, university will pull that student.
Similarly, of we talk about PAN card number,
license number.
You can't do this case a Mandatory field,
To whom would you do the mandatory field
in the case of a student?
Registration number or roll number.
What is the actual concept of primary key?
Primary key is also unique Plus
it is not null.
So I got an advantage from the candidate,
Unique.
It will always be unique,
but out of all candidates key
I'm just one,
The one who is the most appropriate.
Appropriate means like I just told you the case.
In the case of student
the most appropriate will be either
the registration number or roll number.
If it is a small college,
then you can also take the roll number.
If there are universities,
then what you will take, registration number
or serial number as a primary key,
because it is unique,
because it is a candidate key so definitely it is unique
Plus this is not null
You can't leave it empty.
So whenever you talk about this case,
you can pick any database.
In that database,
Your primary key always unique plus not null
and second,
We never take the value of
the primary key from the users.
We give the value of primary key to the user.
So let suppose if you go to a college
or university to take admission
So you won't say sir,
I want this roll number
or I want this registration number.
that I want a VIP registration number,
there is no such thing.
They will give you automatically generated
whether this is your registration number
or roll number,
because this field can't be leave empty.
Similarly, Let suppose if you go to the passport office
What will be the passport number
at the passport office?
It will be primary key
because it is also unique,
plus not null.
Now in the passport office, data of the
same student's sorry, same people's will be there, right?
Those who have a passport
means those who have applied for a passport.
Now, do you ask for the passport number by yourself,
No.
They will give you the passport number,
that is the primary key.
Similarly in the license office,
If you applying for the license,
then the license office will have the data
of those people whose license has been
applied already or they have already have
taken the proper or learning license.
So the license number will also be
provided you by the office.
Because this is the very very tough field
means it becomes tough somewhere.
Because unique and not null both
has to be achieved.
Data should be unique and also not null
means you can't even leave that field empty
and even can't fill the duplicate here.
So this is the main concept of the primary key.
Always remember,
the primary key is always unique plus not null.
but the candidate key is only unique.
You can leave it empty,
you can skip it,
but If you don't want skip it,
then what will you made it, primary key.
So the last point here is,
in a database
more than one means 2, 3, 4 primary key,
can be possible?
No,
there must be only one primary
because I told you first,
to make a primary key is very hard
You can neither leave it empty
nor you can fill the duplicates in it.
So if you try to make more than one
attribute the primary key,
then although at first your database will not be allowed.
Any server, Any software you are using
Whether you are using Oracle,
Sequel server, IBM anyone will not allow you.
Because why would I hire two person
my work is getting done by one person?
Same thing here also if my work is
getting done by one attribute,
then I will not mess with multiple attributes.
So that's why your software doesn't even allow you.
to make more than one primary key.
But yes, more than one candidate key can be possible,
because the unique multiple attribute can be possible.
Alone not null also possible.
You can also make more than one attribute, not null.
But if we talk about combinedly,
unique and not null,
it will be just an attribute
and we called it primary key.
That will depends on the database
that you are creating in which scenario.
It will become in the student's case.
In the case of Aadhaar card, Aadhaar card number will be made.
In case of PAN, pan number will be made.
In case of passport, passport number.
In the case of license, license number.
So whatever the database you will talk about,
in that cases you will understand,
what is the concept of primary key.
Thank you.
浏览更多相关视频
Keys in RDBMS
Lec-8: What is CANDIDATE KEY and PRIMARY key | Full Concept | Most suitable examples | DBMS
Lec-22: Finding Closure of Functional dependency in DBMS | Easiest & Simplest way
Lec-8.0: Integrity Constraints in Database with Examples
Database Key fields - animation
Lec-10: Foreign Key in DBMS | Full Concept with examples | DBMS in Hindi
5.0 / 5 (0 votes)