DBMS Concepts

DBMS Tutorial Components of DBMS. Applications of DBMS The difference between file system and DBMS. Types of DBMS DBMS Architecture DBMS Schema Three Schema Architecture. DBMS Languages.

DBMS ER Model

ER model: Entity Relationship Diagram (ERD) Components of ER Model. DBMS Generalization, Specialization and Aggregation.

DBMS Relational Model

Codd’s rule of DBMS Relational DBMS concepts Relational Integrity Constraints DBMS keys Convert ER model into Relational model Difference between DBMS and RDBMS Relational Algebra DBMS Joins

DBMS Normalization

Functional Dependency Inference Rules Multivalued Dependency Normalization in DBMS: 1NF, 2NF, 3NF, BCNF and 4NF

DBMS Transaction

What is Transaction? States of transaction ACID Properties in DBMS Concurrent execution and its problems DBMS schedule DBMS Serializability Conflict Serializability View Serializability Deadlock in DBMS Concurrency control Protocols

Difference

Difference between DFD and ERD

Misc

Advantages of DBMS Disadvantages of DBMS Data Models in DBMS Relational Algebra in DBMS Cardinality in DBMS Entity in DBMS Attributes in DBMS Data Independence in DBMS Primary Key in DBMS Foreign Key in DBMS Candidate Key in DBMS Super Key in DBMS Aggregation in DBMS Hashing in DBMS Generalization in DBMS Specialization in DBMS View in DBMS File Organization in DBMS What Is A Cloud Database What Is A Database Levels Of Locking In DBMS What is RDBMS Fragmentation in Distributed DBMS What is Advanced Database Management System Data Abstraction in DBMS Checkpoint In DBMS B Tree in DBMS BCNF in DBMS Advantages of Threaded Binary Tree in DBMS Advantages of Database Management System in DBMS Enforcing Integrity Constraints in DBMS B-Tree Insertion in DBMS B+ Tree in DBMS Advantages of B-Tree in DBMS Types of Data Abstraction in DBMS Levels of Abstraction in DBMS 3- Tier Architecture in DBMS Anomalies in Database Management System Atomicity in Database Management System Characteristics of DBMS DBMS Examples Difference between Relational and Non-Relational Databases Domain Constraints in DBMS Entity and Entity set in DBMS ER Diagram for Banking System in DBMS ER Diagram for Company Database in DBMS ER Diagram for School Management System in DBMS ER Diagram for Student Management System in DBMS ER Diagram for University Database in DBMS ER Diagram of Company Database in DBMS Er Diagram Symbols and Notations in DBMS How to draw ER-Diagram in DBMS Integrity Constraints in DBMS Red-Black Tree Deletion in DBMS Red-Black Tree Properties in DBMS Red-Black Tree Visualization in DBMS Redundancy in Database Management System Secondary Key in DBMS Structure of DBMS 2-Tier Architecture in DBMS Advantages and Disadvantages of Binary Search Tree Closure of Functional Dependency in DBMS Consistency in Database Management System Durability in Database Management System ER Diagram for Bank Management System in DBMS ER Diagram for College Management System in DBMS ER Diagram for Hotel Management System in DBMS ER Diagram for Online Shopping ER Diagram for Railway Reservation System ER Diagram for Student Management System in DBMS Isolation in DBMS Lossless Join and Dependency Preserving Decomposition in DBMS Non-Key Attributes in DBMS Data Security Requirements in DBMS DBMS functions and Components What is Homogeneous Database? DBMS Functions and Components Advantages and Disadvantages of Distributed Database Relational Database Schema in DBMS Relational Schema

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 process. There are several types of constraints that can be implemented on the database during the CRUD operations and other processes. They limit the entry of data or the data type of the data or both. These Constraints are also known as Integrity Constraints.

Types of Constraints

  • Domain Constraints
  • Entity Integrity Constraints
  • Referential Integrity Constraints
  • Key Constraints
  • NOT NULL
  • UNIQUE
  • DEFAULT
  • CHECK
  • Mapping Constraints

Domain constraint: This constraint specifies a set of values that can be entered as the valid input for the attribute. Datatypes of domain attributes include string, integer, date, time etc. A particular column of a table in a database allows only a single type of data. We cannot have any other datatype value in that column.

Domain constraints are also called user-defined data types. Additionally, it enforces some basic rules that are defined by the user on the column.

Domain Constraint is a combination of the datatypes and special constraints and can be expressed as “data type + Constraints (NOT NULL / UNIQUE /                          PRIMARY KEY / FOREIGN KEY / CHECK / DEFAULT)”

Entity Integrity Constraint: This constraint specify that a primary key cannot hold null as a value as it is used to uniquely identify a record but if null, we won’t be able to identify the entity.

Referential Integrity Constraint: This constraint is applied among different tables. According to this constraint if a foreign key of a table refers to the primary key of that table, then all the values of that foreign key either should be a value from the primary key of that other table or should be a null value. 

Key Constraint: They are two types of key constraints. These are primary key constraints and foreign key constraints.

  • PRIMARY KEY

As discussed earlier, the Primary key can uniquely identify each record in a table. It must have unique values and cannot contain nulls. In the example below we have declared WORKER_ID as the Primary Key of the table. Now no two values of the WORKER_ID can hold the same value and neither can it hold NULL as a value.

CREATE TABLE WORKER(
WORKER_ID INT NOT NULL,
WORKER_NAME VARCHAR (30) NOT NULL,
WORKER_AGE INT NOT NULL,
WORKER_PHONE_NUMBER INT NOT NULL UNIQUE,
WORKER_ADDRESS VARCHAR (200),
PRIMARY KEY (WORKER_ID)
);
  • FOREIGN KEY

Foreign keys are primarily used to refer to the values of another table in the table. It is a key that refers to the primary key of any other table and is allowed to have any value from that primary key column or it should be NULL. They are used to cross-refer the tables.

Not null: This is used to check that no value entered in the particular table should be null. When no value is entered while entering the value of any column a null value is automatically assigned to it. But when we specify this constraint we cannot leave any value empty as the particular column should not have a null value. In such a case, we usually assign a DEFAULT value which is assigned when no value is entered.

Example:

CREATE TABLE WORKER(
WORKER_ID INT,
WORKER_NAME VARCHAR (30) NOT NULL,
WORKER_AGE INT NOT NULL,
WORKER_PHONE_NUMBER INT NOT NULL,
WORKER_ADDRESS VARCHAR (200),
PRIMARY KEY (WORKER_ID)
);

UNIQUE:

UNIQUE as the name suggests this keyword is used to ensure that no two values of the particular column have the same values. In the example below, WORKER_PHONE_NUMBER is limited with this constraint. No, two employees can have the same value in this database.

CREATE TABLE WORKER(
WORKER_ID INT NOT NULL,
WORKER_NAME VARCHAR (30) NOT NULL,
WORKER_AGE INT NOT NULL,
WORKER_PHONE_NUMBER INT NOT NULL UNIQUE,
WORKER_ADDRESS VARCHAR (200),
PRIMARY KEY (WORKER_ID)
);

DEFAULT:

In the DEFAULT constraint, we can assign a specified value to a column, this value is assigned where the value is left by the user empty. If there is no value assigned to WORKER_SALARY, then instead of a NULL value 10000 will be assigned as that employee’s salary.

CREATE TABLE WORKER(
WORKER_ID INT NOT NULL,
WORKER_NAME VARCHAR (30) NOT NULL,
WORKER_SALARY INT DEFAULT 10000,
WORKER_AGE INT NOT NULL,
WORKER_PHONE_NUMBER INT NOT NULL,
WORKER_ADDRESS VARCHAR (200),
PRIMARY KEY (WORKER_ID)
);

CHECK:

This keyword is used to enclose the values of the particular column in a finite set. When we can implement this constraint to determine the extreme values of the column. The value feed to the column should hold to this condition, if not the value won’t be accepted as an entry. Here an error will be raised if the WORKER_SALARY is more than the specified range that is 100000.

CREATE TABLE WORKER(
WORKER_ID INT NOT NULL,
WORKER_NAME VARCHAR (30) NOT NULL,
WORKER_SALARY INT CHECK (WORKER_SALARY <100000),
WORKER_AGE INT NOT NULL,
WORKER_PHONE_NUMBER INT NOT NULL,
WORKER_ADDRESS VARCHAR (200),
PRIMARY KEY (WORKER_ID)
);