Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
Difference between Delay and Deadline Constraint in Real-time System
Next article icon

Difference between Entity constraints, Referential constraints and Semantic constraints

Last Updated : 04 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Constraints are used in relational databases to follow the standards of the database and guarantee that the data is valid. Users are usually confused about various kinds of constraints most of which include entity constraints, referential constraints and semantic constraints.

In this article, We will learn about the Difference between Entity constraints, Referential constraints and Semantic constraints and so on.

What is Entity constraints?

These constraints are given within one table. The entity constraints are primary key, foreign key, unique. Entity constraints are those constraints that limit the data entered in any one cell or entity of the table at a time.

These constraints mostly revolve around the issue of variance, which is a measure of the distinctive authenticity of the data.

Example:

create table student (rollnumber int primary key, name varchar2(30), course varchar2(10));
Insert into student values(111, 'ABC', 'Chemical');
Insert into student values(112, 'JJP', 'Mech');

Output:

Rollnumber Name Course
111 ABC Chemical
112 JJP Mech

These values are inserted in the table. Suppose a value given below is inserted :

Insert into student values(111, 'MAB', 'EEE');

It gives an error as the roll-number is enforced a primary key constraint that refrains from duplication. These constraints ensures to maintain uniqueness in the tables to avoid duplication’s.

Types of Entity Constraints

  • Primary Key Constraint: It Provides a means of identifying uniqueness for each row in a table.
  • Unique Constraint: Similar to a primary key but a column can contain one NULL value.
  • NOT NULL Constraint: It Blocks the possibility of entering NULL values into a column.

Advantages of Entity Constraints

  • Data Integrity: There is no repetition or entry of invalid data into the record book.
  • Improved Searchability: It Retrieves data faster since data must have unique keys to be put into the database.
  • Consistency: Provids for rational and coherent data input and storage.

Disadvantages of Entity Constraints

  • Overhead: It May result in delays when working on insert and update processes.
  • Rigidity: Makes it a little difficult when it comes to data insertion.

What is Referential constraints?

These constraints are used for referring other tables to enforce conditions on the data. The widely used referential constraint is foreign key. Referential integrity guarantees referential integrity, that is, the referential link between tables is consistent.

They keep the relationship between tables intact as keys in one table refer to keys in other tables at the same time.

Example:

create table marks (rollnumber int, name varchar2(30), course varchar2(30)
references student, marks int);

A table is created with a constraint that the marks should be rewarded to those students that are pursuing courses stated in the student table only. If a user tries to enter a value that doesn’t exist, it returns an error.

Types of Referential Constraints

  • Foreign Key Constraint: It Checks that a column (or set of columns) points to a row in another table (often used in HDFS).

Advantages of Referential Constraints

  • Maintains Data Relationships: It helps in maintaining integrity of reference between tables always.
  • Cascading Updates/Deletes: It Corrects related rows or deleted to ensure the data recorded in the table is synchronized with other applications.

Disadvantages of Referential Constraints

  • Complexity: It Introduces difficulties in managing a database.
  • Performance Overhead: May cause a deceleration of operations that involve related tables.

What is Semantic constraints?

Datatypes are the semantic constraints enforced in a table. Datatypes help the data segregate according to its type. Semantic constraints are rules that capture the meaning or the context of the data. Another type of business rules they implement are not structure related rather they are logical correctness of data.

Example :

A name is a combination of different letters. We can place the name column in the char datatype yet char doesn’t satisfy the condition thereby varchar is preferably used for name.

name varchar2(30);

Examples of Semantic Constraints

  • Age Validation: It Verifying a person’s age to be greater than a certain value.
  • Salary Constraints: A provision that no salary can be more than a set amount for some positions.

Advantages of Semantic Constraints

  • Business Logic Enforcement: Confirms that all data agreed to the business rules set.
  • Higher Data Quality: Enhances the work’s quality since the data is made relevant and more correct.

Disadvantages of Semantic Constraints

  • Complex Rule Definition: They can easily be evaded and thus become hard when setting rules on them.
  • Application-Specific: It May need to be updated from time to time whenever there is a change in business requirements.

Difference between Entity Constraints, Referential Constraints and Semantic Constraints

Characteristics Entity constraints Referential constraints Semantic constraints
Definition Entity constraints are posed within a table. Referential constraints are enforced with more than one table. Semantic constraints are enforced on the values of a specific attribute .
Kinds The entity constraints are: unique, primary key, NULL. The referential constraints are foreign key. The semantic constraints are the datatypes.
Description These constraints are used to enforce uniqueness in a table( while NULL is used to define no value) These constraints are used for referring to another table for analysis of the data. These constraints are used to divide a set of particular value based on a category.
Functions These constraints ensure non duplicate’s in a database. These constraints ensure that consistency of a database. These constraints ensure that values are categorized accordingly to avoid confusions.
Syntax Primary key: create table( column1 datatype1 primary key…) Foreign key: create table( column1 datatype1 references tablename…) column1 varchar2(30)
Examples No two students can be designated the same rollnumber. Rollnumber being referred to the marks table. Name is assigned to varchar2 with a precision of 50.

Conclusion

Entity, referential and semantic integrity constraints are very important in maintaining integrity, validity and consistency of data within the context of a relational database. Whereas entity constraints are placed on the individual data items, referential constraints are applied to the relation between the table and semantic constraints are applied based on the meaning of the data. Knowledge of and adherence to such bounds contribute to the enhancement of the reliability of a database.



Next Article
Difference between Delay and Deadline Constraint in Real-time System

M

mangalgiaishwarya2
Improve
Article Tags :
  • Databases
  • Difference Between
  • SQL

Similar Reads

  • Difference between Delay and Deadline Constraint in Real-time System
    Prerequisite - Timing Constraints in Real-time System 1. Delay Constraint : Delay constraint is the minimum time interval between occurrence of two consecutive events in the real-time system. If an event occurs before the delay constraint, then it is called a delay violation. The time interval betwe
    2 min read
  • Difference between Data Security and Data Integrity
    Data protection and integrity have become very important in this modern world for organizations, companies, and even for the people. Unique, basic, and important to the theme here are two concepts Data Security and Data Integrity. Although both oversee separate ideas in the sector of data management
    6 min read
  • Difference between Database and Search Engine
    A database and a search engine are both tools for finding information, but how they do this and what types of problems they solve differ greatly. Think of a database as an orderly virtual cabinet where you keep all your structured data — think of pieces like names, addresses, or sales records. It is
    6 min read
  • Cascading Referential Integrity Constraints in SQL Server Management Studio
    In the Microsoft SQL server if we want to delete any record or column from one table but that record or column is a foreign key for another table then we will get the error to solve this problem we use Cascading referential integrity constraint. It allows the actions that SQL Server should take when
    4 min read
  • Difference between entity, entity set and entity type
    The Entity-Relationship (ER) Model is one of the primary components of Database Management Systems and is very important for designing the logical structure of databases. It helps define data, and the relationship between the data entities and it makes the system easier to visualize. This is the rea
    7 min read
  • Difference between Primary and Candidate Key
    In relational database management systems(RDBMS) both the Primary Key and Candidate Key are the essential components and are used to uniquely identify records (tuples) within a table. They both are fundamental concepts used to ensure data integrity and prevent duplication of data. These(Primary key
    6 min read
  • Difference between Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC)
    When you work on Relational Calculus which is the main concept in Database Theory, you will find two kinds of variations that play an important role. These two variations are Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC). If you want to retrieve data from the database, both TR
    5 min read
  • Difference between Super Key and Candidate Key
    Tables in databases need ways to identify each record uniquely. Super keys and candidate keys help with this. They're special columns or groups of columns that can tell records apart. Both super keys and candidate keys can have empty spaces (null values). These keys also help connect different table
    4 min read
  • Difference between Strong and Weak Entity
    An entity is a “thing” or “object” in the real world. An entity contains attributes, which describe that entity. So anything about which we store information is called an entity. Entities are recorded in the database and must be distinguishable, i.e., easily recognized from the group. In this articl
    3 min read
  • Difference between Physical and Logical Data Independence
    Data Independence therefore refers to the nature whereby one can change the structure of the database without having to change its implementation or data. There are two types of data independence: The first type is the Physical one as well as the second type is the Logical one. As will be seen, both
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences