0% found this document useful (0 votes)
9 views9 pages

What Is Constraint

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

What Is Constraint

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Copyright© 2023 Mohammed Abu-Hadhoud

ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Copyright© 2023 Mohammed Abu-Hadhoud
ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
What is Constraint?

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Data Integrity

Primary Key
Employees Table
ID FirstName LastName Gender Birthdate Salary DepartmentID
Primary Key
1 U@s#5#Z|9E Abu‐Hadhoud M 6/11/1977 ‐400 1

2 Ali Zaher M 5/7/1990 3000 2 Departments Table


ID Name Location
3 Lubna 1/1/2000 F Hamdi 500 1

1 IT Amman
5 Fadi Khalil M 6/6/1980 1400 4

2 Finance Amman
6 Maha Majed M 7/7/2001 300 3

3 HR UAE
7 Omar Ali M 6/6/1977 2000 1

4 Marketing Qatar
8 Huda Omar F 4/2/1990 1000 5

Foreign Key

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Constraints
• In the context of databases, constraints are rules or conditions that are
applied to the data to ensure its integrity and consistency. Constraints
can be applied to individual columns or to entire tables, and they are used
to enforce various rules and restrictions on the data.

• By using constraints, you can help ensure that your data is accurate,
consistent, and easy to manage.

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Constraints
Here are some common types of constraints used in databases:

1.Primary Key Constraint: This constraint ensures that a column or a set of


columns uniquely identifies each row in a table. This constraint helps to
enforce data integrity and ensure that there are no duplicate rows in the table.

2.Foreign Key Constraint: This constraint establishes a relationship between two


tables based on a key field. The foreign key constraint ensures that data in one
table matches data in another table, and it helps to maintain referential
integrity in the database.

3.Unique Constraint: This constraint ensures that the data in a column or set of
columns is unique across all rows in the table. This constraint helps to enforce
data integrity and prevent duplicate values from being inserted into the table.

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Constraints
Here are some common types of constraints used in databases:

4. Not Null Constraint: This constraint ensures that a column or set of


columns cannot contain null (empty) values. This constraint helps to ensure
that the data is complete and accurate, and it can help prevent errors in
queries and calculations.

5. Check Constraint: This constraint ensures that the data in a column or set
of columns meets a specified condition. This constraint helps to enforce data
integrity and prevent invalid data from being inserted into the table.

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Interview Question?
What is the difference between Primary Key Constraint and Unique Constraint?

Primary Key is Unique but it does not allow NULL  while Unique allows NULL.

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Copyright© 2023 Mohammed Abu-Hadhoud
ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience

You might also like