SlideShare una empresa de Scribd logo
1 de 15
Integrity Constraints
By:
Megha Yadav
Integrity Constraints
• Integrity constraints are used to ensure accuracy and consistency of the data in a
relational database.
• Data integrity is handled in a relational database through the concept of referential integrity.
• Integrity constraints are a set of rules. It is used to maintain the quality of information.
• Integrity constraints ensure that the data insertion, updating, and other processes have to be
performed in such a way that data integrity is not affected.
• Thus, integrity constraint is used to guard against accidental damage to the database.
Types of Integrity Constraints
Domain constraint
• Domain constraints can be defined as the definition of a valid set of values
for an attribute. The data type of domain includes string, character, integer,
time, date, currency, etc.
• Domain constraint are :
Not null
Unique
Check (<predicate>)
NOT NULL Constraint
• By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values.
This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without
adding a value to this field.
Example
CREATE TABLE STUDENT(
ROLL_NO INT NOT NULL ,
STU_NAME VARCHAR (35) NOT NULL,
STU_AGE INT NOT NULL,
EXAM_FEE INT DEFAULT 10000,
STU_ADDRESS VARCHAR (35) ,
PRIMARY KEY (ROLL_NO) )
• In the above example we have set the not null constraint on ROLL_NO column of STUDENT table. Now the roll no
values can not be null .
UNIQUE constraint
• UNIQUE Constraint enforces a column or set of columns to have unique values.
• If a column has a unique constraint, it means that particular column cannot have
duplicate values in a table.
CREATE TABLE STUDENT
(ROLL_NO INT NOT NULL UNIQUE,
STU_NAME VARCHAR (35) NOT NULL ,
STU_AGE INT NOT NULL,
STU_ADDRESS VARCHAR (35) PRIMARY KEY (ROLL_NO)
);
Now the roll number is set to be unique ,which means no two similar values of roll number is
accepted .
CHECK constraint
• The check clause :This constraint is used for specifying range of values for a particular column of a table.
• When this constraint is being set on a column, it ensures that the specified column must have the value
falling in the specified range
CREATE TABLE STUDENT(
ROLL_NO INT CHECK(ROLL_NO >1000) ,
STU_NAME VARCHAR (35) NOT NULL,
STU_AGE INT NOT NULL,
EXAM_FEE INT DEFAULT 10000,
STU_ADDRESS VARCHAR (35) ,
PRIMARY KEY (ROLL_NO) );
In the above example we have set the check constraint on ROLL_NO column of STUDENT table. Now, the
ROLL_NO field must have the value greater than 1000.
Entity integrity constraints
• The entity integrity constraint states that primary key value can't be null.
This is because the primary key value is used to identify individual rows in
relation and if the primary key has a null value, then we can't identify those
rows. A table can contain a null value other than the primary key field.
• In the diagram ,say Emp_Id is primary key in the table. Thus from the
definition of Entity Integrity, the value of Emp_Id cannot be null as it
unique identifies an employee record in the table.
• Thus no primary key column of any row in a table can have a null value.
Referential integrity
• Referential integrity refers to the accuracy and consistency of data within a
relationship. In relationships, data is linked between two or more tables.
• This is achieved by having the foreign key (in the associated table) reference a
primary key value (in the primary – or parent – table).
• As a Relational Database Management System (RDBMS), SQL Server uses
the referential integrity constraint to ensure that data in one table points to
data in another table—and doesn't point to data that doesn't exist.
• SQL Server uses constraints, triggers, rules, and defaults to
enforce referential integrity.
Example
• For example, if we delete record number 15 in a primary table, we need to be
sure that there’s no foreign key in any related table with the value of 15. We
should only be able to delete a primary key if there are no associated
records. Otherwise, we would end up with an orphaned record.
• So referential integrity will prevent users from:
• Adding records to a related table if there is no associated record in the
primary table.
• Changing values in a primary table that result in orphaned records in a
related table.
• Deleting records from a primary table if there are matching related records.
Integrity Constraints

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
Relational model
Relational modelRelational model
Relational model
 
RELATIONSHIP IN DBMS.pptx
RELATIONSHIP IN DBMS.pptxRELATIONSHIP IN DBMS.pptx
RELATIONSHIP IN DBMS.pptx
 
Sql Server Basics
Sql Server BasicsSql Server Basics
Sql Server Basics
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
 
Database language
Database languageDatabase language
Database language
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Database abstraction
Database abstractionDatabase abstraction
Database abstraction
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 
Data independence
Data independenceData independence
Data independence
 
Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)
 

Similar a Integrity Constraints

Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai1
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai
 
Joins & constraints
Joins & constraintsJoins & constraints
Joins & constraintsVENNILAV6
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxYashaswiniSrinivasan1
 
Null Values.ppt briefing about null values in SQL. Very helpful if you are le...
Null Values.ppt briefing about null values in SQL. Very helpful if you are le...Null Values.ppt briefing about null values in SQL. Very helpful if you are le...
Null Values.ppt briefing about null values in SQL. Very helpful if you are le...shalinigambhir3
 
Sql ch 9 - data integrity
Sql ch 9 - data integritySql ch 9 - data integrity
Sql ch 9 - data integrityMukesh Tekwani
 
5. relational structure
5. relational structure5. relational structure
5. relational structurekhoahuy82
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelKunal Anand
 
ER Digramms by Harshal wagh
ER Digramms by Harshal waghER Digramms by Harshal wagh
ER Digramms by Harshal waghharshalkwagh999
 
Database Terminology and DBLC.pptx
Database Terminology and DBLC.pptxDatabase Terminology and DBLC.pptx
Database Terminology and DBLC.pptxTop1064
 

Similar a Integrity Constraints (20)

Database constraints
Database constraintsDatabase constraints
Database constraints
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Joins & constraints
Joins & constraintsJoins & constraints
Joins & constraints
 
ER diagram
ER diagramER diagram
ER diagram
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Pre-sentation.pdf
Pre-sentation.pdfPre-sentation.pdf
Pre-sentation.pdf
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Null Values.ppt briefing about null values in SQL. Very helpful if you are le...
Null Values.ppt briefing about null values in SQL. Very helpful if you are le...Null Values.ppt briefing about null values in SQL. Very helpful if you are le...
Null Values.ppt briefing about null values in SQL. Very helpful if you are le...
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Sql ch 9 - data integrity
Sql ch 9 - data integritySql ch 9 - data integrity
Sql ch 9 - data integrity
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
 
Relational data model
Relational data modelRelational data model
Relational data model
 
DATABASE-1.pptx
DATABASE-1.pptxDATABASE-1.pptx
DATABASE-1.pptx
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data Model
 
ER Digramms by Harshal wagh
ER Digramms by Harshal waghER Digramms by Harshal wagh
ER Digramms by Harshal wagh
 
Database Terminology and DBLC.pptx
Database Terminology and DBLC.pptxDatabase Terminology and DBLC.pptx
Database Terminology and DBLC.pptx
 

Más de Megha yadav

What is Numerical And Categorical Data .pptx
What is Numerical And Categorical Data .pptxWhat is Numerical And Categorical Data .pptx
What is Numerical And Categorical Data .pptxMegha yadav
 
Overview of DBMS/Introduction to DBMSpptx
Overview of DBMS/Introduction to DBMSpptxOverview of DBMS/Introduction to DBMSpptx
Overview of DBMS/Introduction to DBMSpptxMegha yadav
 
Types of RPA BOT and Tools
Types of RPA BOT and ToolsTypes of RPA BOT and Tools
Types of RPA BOT and ToolsMegha yadav
 
Introduction to RPA
Introduction to RPAIntroduction to RPA
Introduction to RPAMegha yadav
 
Digital Marketing Syllabus
Digital Marketing Syllabus Digital Marketing Syllabus
Digital Marketing Syllabus Megha yadav
 
Structure of dbms
Structure of dbmsStructure of dbms
Structure of dbmsMegha yadav
 
Security and Authorization
Security and AuthorizationSecurity and Authorization
Security and AuthorizationMegha yadav
 
Distributed Computing
Distributed Computing Distributed Computing
Distributed Computing Megha yadav
 
Cluster computing
Cluster computingCluster computing
Cluster computingMegha yadav
 
Introduction to SEO
Introduction to SEOIntroduction to SEO
Introduction to SEOMegha yadav
 
Website Architecture
Website ArchitectureWebsite Architecture
Website ArchitectureMegha yadav
 

Más de Megha yadav (12)

What is Numerical And Categorical Data .pptx
What is Numerical And Categorical Data .pptxWhat is Numerical And Categorical Data .pptx
What is Numerical And Categorical Data .pptx
 
Overview of DBMS/Introduction to DBMSpptx
Overview of DBMS/Introduction to DBMSpptxOverview of DBMS/Introduction to DBMSpptx
Overview of DBMS/Introduction to DBMSpptx
 
Types of RPA BOT and Tools
Types of RPA BOT and ToolsTypes of RPA BOT and Tools
Types of RPA BOT and Tools
 
Introduction to RPA
Introduction to RPAIntroduction to RPA
Introduction to RPA
 
Digital Marketing Syllabus
Digital Marketing Syllabus Digital Marketing Syllabus
Digital Marketing Syllabus
 
Structure of dbms
Structure of dbmsStructure of dbms
Structure of dbms
 
Security and Authorization
Security and AuthorizationSecurity and Authorization
Security and Authorization
 
Grid computing
Grid computingGrid computing
Grid computing
 
Distributed Computing
Distributed Computing Distributed Computing
Distributed Computing
 
Cluster computing
Cluster computingCluster computing
Cluster computing
 
Introduction to SEO
Introduction to SEOIntroduction to SEO
Introduction to SEO
 
Website Architecture
Website ArchitectureWebsite Architecture
Website Architecture
 

Último

Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 

Último (20)

Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 

Integrity Constraints

  • 2. Integrity Constraints • Integrity constraints are used to ensure accuracy and consistency of the data in a relational database. • Data integrity is handled in a relational database through the concept of referential integrity. • Integrity constraints are a set of rules. It is used to maintain the quality of information. • Integrity constraints ensure that the data insertion, updating, and other processes have to be performed in such a way that data integrity is not affected. • Thus, integrity constraint is used to guard against accidental damage to the database.
  • 3. Types of Integrity Constraints
  • 4. Domain constraint • Domain constraints can be defined as the definition of a valid set of values for an attribute. The data type of domain includes string, character, integer, time, date, currency, etc. • Domain constraint are : Not null Unique Check (<predicate>)
  • 5. NOT NULL Constraint • By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field. Example CREATE TABLE STUDENT( ROLL_NO INT NOT NULL , STU_NAME VARCHAR (35) NOT NULL, STU_AGE INT NOT NULL, EXAM_FEE INT DEFAULT 10000, STU_ADDRESS VARCHAR (35) , PRIMARY KEY (ROLL_NO) ) • In the above example we have set the not null constraint on ROLL_NO column of STUDENT table. Now the roll no values can not be null .
  • 6. UNIQUE constraint • UNIQUE Constraint enforces a column or set of columns to have unique values. • If a column has a unique constraint, it means that particular column cannot have duplicate values in a table. CREATE TABLE STUDENT (ROLL_NO INT NOT NULL UNIQUE, STU_NAME VARCHAR (35) NOT NULL , STU_AGE INT NOT NULL, STU_ADDRESS VARCHAR (35) PRIMARY KEY (ROLL_NO) ); Now the roll number is set to be unique ,which means no two similar values of roll number is accepted .
  • 7. CHECK constraint • The check clause :This constraint is used for specifying range of values for a particular column of a table. • When this constraint is being set on a column, it ensures that the specified column must have the value falling in the specified range CREATE TABLE STUDENT( ROLL_NO INT CHECK(ROLL_NO >1000) , STU_NAME VARCHAR (35) NOT NULL, STU_AGE INT NOT NULL, EXAM_FEE INT DEFAULT 10000, STU_ADDRESS VARCHAR (35) , PRIMARY KEY (ROLL_NO) ); In the above example we have set the check constraint on ROLL_NO column of STUDENT table. Now, the ROLL_NO field must have the value greater than 1000.
  • 8. Entity integrity constraints • The entity integrity constraint states that primary key value can't be null. This is because the primary key value is used to identify individual rows in relation and if the primary key has a null value, then we can't identify those rows. A table can contain a null value other than the primary key field. • In the diagram ,say Emp_Id is primary key in the table. Thus from the definition of Entity Integrity, the value of Emp_Id cannot be null as it unique identifies an employee record in the table. • Thus no primary key column of any row in a table can have a null value.
  • 9.
  • 10. Referential integrity • Referential integrity refers to the accuracy and consistency of data within a relationship. In relationships, data is linked between two or more tables. • This is achieved by having the foreign key (in the associated table) reference a primary key value (in the primary – or parent – table).
  • 11. • As a Relational Database Management System (RDBMS), SQL Server uses the referential integrity constraint to ensure that data in one table points to data in another table—and doesn't point to data that doesn't exist. • SQL Server uses constraints, triggers, rules, and defaults to enforce referential integrity.
  • 12. Example • For example, if we delete record number 15 in a primary table, we need to be sure that there’s no foreign key in any related table with the value of 15. We should only be able to delete a primary key if there are no associated records. Otherwise, we would end up with an orphaned record.
  • 13.
  • 14. • So referential integrity will prevent users from: • Adding records to a related table if there is no associated record in the primary table. • Changing values in a primary table that result in orphaned records in a related table. • Deleting records from a primary table if there are matching related records.