×

Primary Key in DBMS

Primary Key in DBMS: A primary key is the minimal set of columns in the database table, which uniquely identifies each row or tuple in that table. Any table in the database cannot contain more than one primary key. All the values are different from each other in the column, which is defined as the primary key.

It is a key that is a distinct identifier for a record in the database. When we created the table, we typically have to assign the one column or field as the primary key.

Following are the two characteristics of the Primary key in DBMS:

  • In the table, two tuples cannot have the same value, i.e., duplicate values cannot exist.
  • The field or column, which is defined as the primary key, cannot have a NULL value.
  • There is only one primary can be assigned in a table.

We are describing the primary key with the following example, so you can easily understand it.

This example uses one table Employee, which contains four columns or fields. The name of four columns is Employee_ID, Employee_Name, Employee_Age, Employee_Salary. Out of these four columns, one column or set of more than one column can be a primary key.

In the table, we cannot define the primary key to Employee_Name, because more than one employee in the table can have the same name. As well as, we cannot define the primary key to Employee_Age and Employee_Salary because, in the table, more than one employee can have the same age and same salary. 

So, we have to only define the Employee_ID as the primary key, because each employee has a unique ID, which uniquely identifies employee record in the table.

Employee_ID (Primary Key)Employee_NameEmployee_AgeEmployee_Salary
101Arjun2880,000
102Bheem2645,000
103Amit2440,000
104Karan2240,000
105Shadev2445,000
106Amit2335,000

Create the Primary Key in RDBMS

We have learned the meaning of the primary key with the example. Now, we will discuss how to create the primary key in the SQL. So, we will take the above table to create the primary key. In SQL, we can create the primary key as shown below:

Create table Employee
(
    Employee_Id int primary key,
    Employee_Name varchar(255) not null,
    Employee_Age int not null,
    Employee_Salary int not null
);

If we do not define the primary key to the field at the time of table creation, then we can also define it later as same as shown below:

ALTER TABLE Employee
ADD CONSTRAINT PK_Employee PRIMARY KEY (Employee_ID);


Related Topics

What is Transaction in DBMS

A transaction is a collection of logically related operations which reads and possibly updates the various data items in the database. Usually, a transaction is initiated by a user program written in high-level...

3 minutes read.

Concurrent Execution of Transaction

In the transaction process, a system usually allows executing more than one transaction simultaneously. This process is called a concurrent execution. Advantages of concurrent execution of a transaction Decrease waiting time or...

4 minutes read.

Three Schema Architecture of DBMS

The three schema architecture describes how the data is represented or viewed by the user in the database. This architecture is also known as three-level architecture and is sometimes called...

3 minutes read.

Multivalued Dependency

Multivalued Dependency exists in a relation when two attributes depend on the third attribute but independent to each other. It is a full constraint between two sets of attributes in a relation. It...

2 minutes read.

DBMS Architecture

Architecture of Database Management System DBMS architecture helps in development, implementation, design, and maintenance of a database that store and organize information for agencies, businesses, and institutions. It is the base of any database...

2 minutes read.

BCNF in DBMS

BCNF stands for Boyce–Codd Normal Form. What is the Normal form? The normal form is mainly used to reduce the redundancy of the database tables. Or we can say that the normal form...

4 minutes read.

Entity and Entity set in DBMS

What is DBMS? A database management system (DBMS) is a software application that interacts with end-users, other applications, and the database itself to capture and analyze the data. A DBMS allows...

3 minutes read.

ER Diagram for Student Management System in DBMS

Entity Relationship diagrams Entity Relationship Diagrams, or ER Diagrams for short, are diagrams that show the relationships among entity sets that are stored in databases. Alternatively said, ER diagrams assist in...

6 minutes read.

Structure of DBMS

DBMS means Database Management System, which is a tool or software used to create the database or delete, or manipulate the database. Query Processor, Storage Manager, and Disk Storage are the...

3 minutes read.

Integrity Constraints in DBMS

Integrity constraints in DBMS (Database Management System) are used to ensure the accuracy and consistency of data in a database. They are a set of rules that define the allowed...

1 minute read.

Trigger in DBMS

Trigger in DBMS: A trigger is a procedure of SQL statements, which is automatically fired when the DML statements are executed on the table of the database. Triggers are the...

3 minutes read.

Attributes in DBMS

What is Attribute? An attribute is an element in the database management system that describes the property or certain characteristics of the database entity. It is a crucial element of the...

3 minutes read.

Constraints in Database Management System

In a database management system, certain constraints are applied while performing any operation on the database to ensure that the integrity and quality of the data are maintained throughout the...

4 minutes read.

ER Model: Entity Relationship Diagram (ERD) with Examples

ER model stands for Entity-Relationship Model. It is a high-level data model diagram which defines the conceptual view of the database. It is a blueprint or design of a database that will...

2 minutes read.

Difference between File System and DBMS

What is File Management System? A file management system is a collection of programs that manage and store data in files and folders in a computer hard disk. A file management...

9 minutes read.

Difference between DBMS and RDBMS

Database Management System A DBMS is system software which is used to store and manage the data in the database. It was introduced in 1960 for storing the data or information. This system allows...

3 minutes read.

ER Diagram of Company Database in DBMS

Entity Relationship Diagram Entity Relationship Diagrams, or ER Diagrams for short, are diagrams that show the relationships among entity sets that are stored in databases. Alternatively said, ER diagrams assist in...

3 minutes read.

Super Key in DBMS

Super Key in DBMS: The super key is a column or a set of columns in the database table, which uniquely identifies the tuple or row of the same table....

2 minutes read.

Relational Integrity Constraints

Relational Integrity Constraints are the set of rules that can be used to maintain the data integrity during an insert, delete and update operations into a table. These constraints are checked in the...

2 minutes read.

Functional Dependencies

Functional Dependencies (FD) in the relational database management system occurs when one attribute in a relation uniquely determines other attribute in that relation. It describes the relation between the attributes. The term functional...

2 minutes read.