Total Page Preview:   000000000356

What is Unique key in SQL in English and Hindi

 

Unique key in SQL in English

In SQL, a unique key is a set of one or more columns in a table that must contain unique values for each row in the table. This means that no two rows can have the same value for the columns that make up the unique key. Unique keys are used to ensure data integrity and to enforce uniqueness in a table.

Here's an example of how to create a unique key in SQL:
Let's say we have a table named "users" with columns for user ID, first name, last name, and email address. We want to ensure that each email address can only be used once in the table, so we create a unique key on the email column:
 
In this example, we've created a table called "users" with four columns. The first column is the user ID, which we've set as the primary key. The second and third columns are for the user's first and last name. The fourth column is for the user's email address, and we've added the UNIQUE constraint to ensure that each email address can only be used once in the table.
 
If we try to insert a new row into the "users" table with an email address that already exists in the table, we'll get an error because the unique key constraint has been violated.
 
 
 
Unique key in SQL in Hindi
SQL mai unique key ek aisa set hota hai jo table ke ek ya ek se zyada columns ki values ke liye unique hona zaruri hota hai. Ye yeh ensure karta hai ki table ke har row mein unique values hongi. Unique key data integrity ka dhyan rakhne ke liye aur table mein uniqueness enforce karne ke liye use kiya jata hai.
Neechay ek SQL example diya gaya hai jismein unique key ka use kiya gaya hai:
 
Maan lijiye humare paas ek "students" table hai jismein columns hai student ID, first name, last name aur email address ke liye. Hum chahte hain ki har email address table mein sirf ek baar istemal ho, isliye hum email column pe unique key lagaate hain:

Is example mein humne "students" table create kiya hai jismein chaar columns hai. Pehla column student ID hai jo humne primary key set kiya hai. Dusra aur teesra column first name aur last name ke liye hai. Chautha column email address ke liye hai aur humne ispe UNIQUE constraint lagaya hai jisse ki har email address table mein sirf ek baar hi istemal hoga.
 
Agar hum "students" table mein ek row insert karte hain jismein email address pehle se table mein maujood hai to hume error milega kyunki unique 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: