×

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

Advantages of Threaded Binary Tree in DBMS

We know that every node in a binary tree contains both its data value and the address pointers for its left and right children. A null pointer is used to...

3 minutes read.

Foreign key in DBMS

Foreign key in DBMS: The Foreign key is a field or the set of fields in the relational database table, which points to the existing field in another table. 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.

DBMS Examples

Introduction to DBMS A database management system (DBMS) is a software application that is designed to manage and organize data stored in a database. It is responsible for storing, retrieving, and...

4 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.

ER Diagram for University Database in DBMS

What is an ER diagram? ER diagram, short for Entity Relationship Diagram, also known as ERD, is a diagram that shows the relationships of a set of entities stored in a...

9 minutes read.

States of Transaction in DBMS

Transaction States A transaction passes through many different states in its life cycle. These states are known as transaction states. A transaction can be in one of the following states in the database: Active statePartially...

3 minutes read.

Types of DBMS

Database Management System A software that is programmed to enable the user to create and maintain a database. Using DBMS, we can implement create, read, update and delete operations on the...

4 minutes read.

Components of an ER Diagram

An ER Diagram consists of the following components: Entity AttributesRelationships 1. Entity An entity may be an object, place, person, or an event which stores data in the database. In an entity-relationship diagram, an entity...

4 minutes read.

DBMS Architecture

This is the first step when creating a database management system. The architecture of a database management system plays an important role in determining the actual design and layout of...

4 minutes read.

DBMS Data Independence: Logical and Physical

Data Independence in DBMS: Data independence is a concept of DBMS which alters the schema of the database at one level of the database system without altering the schema definition...

2 minutes read.

Redundancy in DBMS

Data redundancy is a situation that is created in the database in which the same amount of data is stored in two different places. The different places are found in a...

3 minutes read.

Conflict Serializability in DBMS

Conflict Serializability A schedule is said to be conflict serializable if it can transform into a serial schedule after swapping of non-conflicting operations. It is a type of serializability that can be used...

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.

DBMS View: Read, Update, Create and Drop

View in DBMS: The View is a logical or virtual table that allows users to view or manipulate parts of the table. View is also a table which consists of...

2 minutes read.

ER Diagram for Company Database in DBMS

What is ER Diagram? An ER diagram (short for Entity Relationship Diagram), also known as an ERD, is a diagram that shows the relationships of a set of entities stored in...

7 minutes read.

DBMS Tutorial | Database Management System

Database Management System (DBMS) tutorial is all about managing and maintaining the data effectively. Our DBMS tutorial is designed for beginners as well as professionals. What is Data? Data is a real-world...

5 minutes read.

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.

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.

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.