EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

DBMS Constraints

Secondary Sidebar
DBMS Tutorial
  • DBMS
    • What is DBMS?
    • Introduction To DBMS
    • DBMS ER Diagram
    • DBMS_RANDOM
    • DBMS_XPLAN
    • DBMS join
    • DBMS Functions
    • Data Administrator in DBMS
    • Checkpoint in DBMS
    • DBMS Table
    • Mapping Constraints in DBMS
    • DBMS Canonical Cover
    • DBMS Log-Based Recovery
    • DBMS Multivalued Dependency
    • View Serializability in DBMS
    • DBMS Concepts
    • DBMS Constraints
    • DBMS_Scheduler
    • B+ Tree in DBMS
    • DBMS_LOB
    • dbms entity
    • DBMS Foreign Key
    • DBMS Users
    • DBMS_Metadata.get_ddl
    • Relational Algebra in DBMS
    • DBMS Components
    • DBMS Features
    • DBMS Models
    • DBMS Relational Model
    • Hashing in DBMS
    • DBMS network model
    • Relationship in DBMS
    • ER Model in DBMS
    • Data Models in DBMS
    • Static Hashing in DBMS
    • Advantages of DBMS
    • dbms_output.put_line
    • DBMS Data Dictionary
    • dbms_xplan.display_cursor
    • Normal Forms in DBMS
    • DBMS helps achieve
    • DBMS 3 tier Architecture
    • Relational Calculus in DBMS
    • Serializability in DBMS
    • File Organization in DBMS
    • DBMS Transaction Processing
    • States of Transaction in DBMS
    • Functional Dependency in DBMS
    • Generalization in DBMS
    • Data Independence in DBMS
    • Lock Based Protocols in DBMS
    • Deadlock in DBMS
    • Integrity Constraints in DBMS
    • Concurrency Control in DBMS
    • Validation Based Protocol in DBMS
    • DBMS Locks
    • Normalization in DBMS
    • Transaction Property in DBMS
    • Specialization in DBMS
    • Aggregation in DBMS
    • Types of DBMS
Home Data Science Data Science Tutorials DBMS Tutorial DBMS Constraints

DBMS Constraints

Introduction to DBMS Constraints

Constraints are very important parts of the dbms, which allows us to impose rules of the data type of data. The main purpose of using constraints is to maintain and provide the integrality while deleting, inserting or updating from the database tables. We have many types of constraints available in dbms, which ensures that we don’t have to handle manually in the code; the dbms constraints will automatically handle it. A few of the types of constraints in dbms are integrality constraints, referential constraints, domain constraints, entity constraints etc.

Relational Model Concepts

The relational model is used to represent a table which consists of rows and columns. Each row in the tables is known as the tuple, and each column of the table is associated with a name which is called as the attribute of the table. These column names are used to identify the type of value stored inside it. Relational model concepts consist of few terminologies.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

  • Domain: It is used to represent the type of value that attribute will hold for a column. That means if the attribute is ‘name’, then it will contain the character, not numeric values inside it. So this decides the domain for the specific attribute.
  • Relational instance: This can be represented by the set of tuples or rows from the table. All these tuples or rows should be unique and should not contain duplicates.
  • Attribute: This concept of the relational model is used to represent the name of the column in a table. An attribute must define the type of an attribute as well. So it is used to represent the column of the table uniquely.
  • Relational key: Relational key can be used to identified the record of the table uniquely. In relational key, every row in that table can have one or more attributes.
  • Relational schema: This concept is used to define our relation model’s name, attribute or column, etc.

Example:

Student_id First_name Last_name

City

1 Abc Xyz Mumbai
2 Pq Ask Pune

Operations in Relational Model

These operations are required to perform anything on the relational model; we have four basic operations that can be used to get the record from the table. By using this, we can easily modify the structure of the model in dbms.

1. SELECT

This is used to get any record from the table or model. We can either select all the records from the table or apply a filter based on the condition we want.

Syntax:

SELECT * FROM table_name WHERE your_condition if any;

This is the basic syntax for using the SELECT statement in a relational model. Let’s see the basic select query to fetch data.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,938 ratings)

Example:

Code:

SELECT * FROM Customers where city = ‘London’;

Output:

DBMS Constraints 1

2. DELETE

This statement can be used to delete the record from the table; also, we can specify the condition with it using the ‘where’ clause.

Syntax:

DELETE FROM table_name WHERE your_condition;

This is the basic syntax for using the DELETE statement in a relational model; let’s see at the basic select query to fetch data.

Example:

Code:

DELETE FROM Customers where city = 'Berlin';

Output:

DELETE

3. INSERT

This is used to insert new records into the table. It will always create a new row inside the table.

Syntax:

INSERT INTO table_name (column1, column2, so on..) VALUES (value1, value2, so on..);

Example:

Code:

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('New Cus', 'Hello', 'some house', 'Mumbai', '400078', 'India');

Output:

DBMS Constraints 3

4. UPDATE

This statement is used to update the records inside the table, which is already existing.

Syntax:

UPDATE Customers
SET ContactName = 'amit verma', City= 'Mumbai'
WHERE CustomerID = 2;

Output:

UPDATE

Examples of DBMS Constraints

Different examples are mentioned below:

Example #1 – Key constraints

This is used to identify the record in the table uniquely, so that means we cannot duplicate the column with key constraints applied.

Id (Key Constraints) First_Name Last_Name
1 Amit Verma
2 Sumit Sharma
1 Anita Verma

Not allowed because Id already present at the table.

Example #2 – Domain constraints

This is used to define the value that an attribute can take. Here age can only be numeric; we cannot insert a string to it.

Id (Key constraints) Name Age (Numeric)
1 Amit Verma 20
2 Sumit Sharma 30
1 Anita Verma ABC

Not allowed because Age is a numeric attribute.

Example #3 – Entity integrity constraints

This is used to indicate the rule on the primary key filed, which cannot contain the null key because we used this to identified the record.

Id (Primary Key) Name Age (Numeric)
1 Amit Verma 20
2 Sumit Sharma 30
Anita Verma ABC

Example #4 – Referential constraints

Related with the foreign key, every foreign key value must be present in the primary key table.

Id (Primary Key) Name Age (Numeric)
1 Amit Verma 20
2 Sumit Sharma 30
3 Anita Verma ABC
Id(Foreign Key) City
1 Mumbai
2 Pune
5 Delhi

Not allowed.

Advantages and Disadvantages of using DBMS Constraints

Given below are the advantages and disadvantages mentioned:

Advantages:

  • It helps us to achieve the data integrity.
  • Need not to handle separately in code by applying checks.
  • Throw exception if anything invalid we try to add.

Disadvantages:

  • Increase complexity
  • Database failure
  • Huge size, cost
  • Performance

Conclusion

By using it, we can take care of our data in the table, all the points seen in the article, which helps us understand when to use this. Easy to use, readable, and maintainable by the developers.

Recommended Articles

This is a guide to DBMS Constraints. Here we discuss the introduction, relational model concepts, operations, examples, advantages & disadvantages. You may also have a look at the following articles to learn more –

  1. DBMS Locks
  2. DBMS 3 tier Architecture
  3. DBMS Components
  4. DBMS Transaction Processing
Popular Course in this category
SQL Training Program (7 Courses, 8+ Projects)
  7 Online Courses |  8 Hands-on Projects |  73+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - SQL Training Program (7 Courses, 8+ Projects) Learn More