Total Page Preview:   000000000357

What is primary key in SQL in English and Hindi

 

Primary key in SQL in English

In MS SQL, a primary key is a column or a set of columns that uniquely identifies each row in a table. The primary key enforces the integrity of the data in the table and ensures that each row has a unique identifier.

A primary key can be a single column or a combination of multiple columns in a table. It cannot contain NULL values, and it must be unique across all the rows in the table.
Here's an example of creating a primary key on a table in MS SQL:
In the above example, we have created a table named "Customers" with four columns - CustomerID, FirstName, LastName, and Email. We have set the CustomerID column as the primary key using the PRIMARY KEY keyword.
If we want to create a primary key on multiple columns, we can use the following syntax:
In the above example, we have created a table named "Orders" with three columns - OrderID, CustomerID, and OrderDate. We have set a primary key on the combination of OrderID and CustomerID columns.
Having a primary key in a table can have many benefits, such as faster data retrieval, improved data integrity, and better query performance. It is considered a best practice to always have a primary key in a table.
 
 

Primary key in SQL in Hindi

MS SQL Server mein, primary key ek aisa column ya set of columns hota hai jo har row ko uniquely identify karta hai. Primary key table ke data integrity ko maintain karta hai aur ensure karta hai ki har row ke paas unique identifier hota hai.

Primary key ek single column ya multiple columns ki combination bhi ho sakta hai. Primary key mein NULL values allow nahi kiye jaate aur yeh table ke saare rows mein unique hona chahiye.

Yahan ek example diya gaya hai jisme ek table mein primary key kaise create kiya jaata hai MS SQL Server mein:
Upar diye gaye example mein humne "Customers" table ko create kiya hai jisme chaar columns hai - CustomerID, FirstName, LastName, aur Email. Humne PRIMARY KEY keyword ka use karke CustomerID column ko primary key ke roop mein set kiya hai.
Agar hum multiple columns par primary key set karna chahte hain toh hum is syntax ka use kar sakte hain:
Upar diye gaye example mein humne "Orders" table ko create kiya hai jisme teen columns hai - OrderID, CustomerID, aur OrderDate. Humne OrderID aur CustomerID columns ki combination par primary key set kiya hai.
Primary key table mein hona kai benefits provide karta hai jaise ki faster data retrieval, improved data integrity, aur better query performance. Isliye, table mein always primary key hona ek best practice 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: