Total Page Preview:   000000000350

What is candidate key in SQL in English and Hindi

 

Candidate key in SQL in English

In SQL, a candidate key is a column or set of columns in a table that can uniquely identify each row of the table. This means that each value in the candidate key must be unique and non-null, and no subset of the candidate key can have the same combination of values.

A candidate key can be used as a primary key for the table, or it can be used to create a unique index for faster searching and retrieval of data.
Here's an example of a candidate key in SQL:
Let's say we have a table named "employees" with columns for employee ID, email address, and phone number. We want to ensure that each row in the table can be uniquely identified by either the employee ID or the email address, so we define both columns as candidate keys:
In this example, we've defined the employee ID as the primary key of the table using the "pk_employees" constraint. We've also defined the email column as a unique column using the "uc_email" constraint. Finally, we've defined a composite candidate key using both the employee ID and email columns, using the "uc_candidate_key" constraint.
By defining the email column as a unique column, we're ensuring that each email address in the table is unique. By defining the employee ID and email columns as a composite candidate key, we're ensuring that each row in the table can be uniquely identified by either the employee ID or the email address.
It's important to note that a table can have multiple candidate keys, but only one primary key. In this example, we've defined the employee ID as the primary key and the email column and the composite candidate key as candidate key

 

 

Candidate key in SQL in Hindi

SQL mai candidate key ek aisa column ya set of columns hota hai jo table ke har row ko uniquely identify kar sakta hai. Ye column ki value unique honi chahiye aur NULL nahi honi chahiye.
Candidate key ka use table ke primary key ke roop mein kiya jata hai ya phir ye ek unique index create karne ke liye bhi use kiya jaa sakta hai.
Neechay ek SQL example diya gaya hai jismein candidate key ka use kiya gaya hai:
Maan lijiye humare paas ek "students" table hai jismein columns hai student ID, email, aur phone number ke liye. Hum chahte hain ki har row ko unique identify kiya jaye to hum student ID aur email dono columns ko candidate key ke roop mein use karenge:
Is example mein humne "students" table create kiya hai jismein paanch columns hai. Pehla column student ID hai jo humne primary key set kiya hai. Dusra aur teesra column email aur phone number ke liye hai. Chautha column student ka first name hai aur paanchva column student ka last name hai.
 
Humne email column pe unique constraint bhi add kiya hai, jisse ki har email address table mein sirf ek baar hi appear ho sakta hai. Iska matlab hai ki do students same email address ka use nahi kar sakte.
Humne student ID aur email dono columns pe composite candidate key constraint bhi add kiya hai, jisse ki har student ko unique identify kiya jaa sake. Iska matlab hai ki har row mein ya to student ID unique hoga ya phir email unique hoga.
 
Agar hum "students" table mein ek row insert karte hain jismein student ID aur email dono columns mein se kuchh ek ya dono ka combination pehle se table mein maujood hai to hume error milega kyunki candidate key constraint ko violate kiya ja raha hai.

 

 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments


                           
                           

                           

                           

Facebook User: