SlideShare ist ein Scribd-Unternehmen logo
1 von 2
How to
specify referential integrity between customer and Rep tables.
Solution
The purpose of using referential integrity is to prevent records that reference other records that
do not exist. It also helps to keep references synchronized .Referential integrity is applied for a
table relationship. Once enforced, Access rejects any operation that would violate referential
integrity for that table relationship. Access rejects updates that change the target of a reference,
and also deletions that remove the target of a reference.
After referential integrity is applied, the following rules apply:
A value cannot be entered in the foreign key field of a related table if that value doesn't exist in
the primary key field of the primary table. If it happens, then records in the second table refer to
records in the primary table which do not exist. They are called orphan records.
Deleting a record from a primary table cannot happen if matching records exist in a related table,
i.e deletion a record from the Customer table if there are orders assigned to that record in the
rep table cannot take place.
Primary key value cannot be changed in the primary table, if doing so would create orphan
records. Example, you cannot change a customer number in the customers table if there are
line items assigned to that customer in the rep table .
The database enforces the rules of this relationship to maintain referential integrity by using a
foreign key which allows declaring that an index in one table is related to an index in another and
allows you to place constraints on what may be done to the table containing the foreign key.
Syntax
FOREIGN KEY [index_name] (index_columns) REFERENCES tbl_name
(index_columns)
Example
SQL> create table customer(cust_id varchar2(10) primary key, cust_name varchar2(20));
SQL> create table rep(no number(3), cust_id varchar2(10) references customer(cust_id));

Weitere ähnliche Inhalte

Ähnlich wie How to specify referential integrity between customer and Rep tables-S.docx

Sql Interview Questions
Sql Interview QuestionsSql Interview Questions
Sql Interview Questions
arjundwh
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
Mukesh Tekwani
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
Iblesoft
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
Koteswari Kasireddy
 

Ähnlich wie How to specify referential integrity between customer and Rep tables-S.docx (20)

Sql
SqlSql
Sql
 
Sql Interview Questions
Sql Interview QuestionsSql Interview Questions
Sql Interview Questions
 
Sql
SqlSql
Sql
 
Sql
SqlSql
Sql
 
153680 sqlinterview
153680  sqlinterview153680  sqlinterview
153680 sqlinterview
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Database design normalization note and exercise
Database design normalization note and exerciseDatabase design normalization note and exercise
Database design normalization note and exercise
 
Joins & constraints
Joins & constraintsJoins & constraints
Joins & constraints
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
 
joins dbms.pptx
joins dbms.pptxjoins dbms.pptx
joins dbms.pptx
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
Fg d
Fg dFg d
Fg d
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
 

Mehr von hamblymarta

Choose all that apply- Which of the following is something that all ce.docx
Choose all that apply- Which of the following is something that all ce.docxChoose all that apply- Which of the following is something that all ce.docx
Choose all that apply- Which of the following is something that all ce.docx
hamblymarta
 
Case Study- Data-Driven Transformation of Springfield's Police Force S.docx
Case Study- Data-Driven Transformation of Springfield's Police Force S.docxCase Study- Data-Driven Transformation of Springfield's Police Force S.docx
Case Study- Data-Driven Transformation of Springfield's Police Force S.docx
hamblymarta
 
Can you please help me answer these two multiple choice questions- Tha.docx
Can you please help me answer these two multiple choice questions- Tha.docxCan you please help me answer these two multiple choice questions- Tha.docx
Can you please help me answer these two multiple choice questions- Tha.docx
hamblymarta
 
can someome please write the init method please This interface defines.docx
can someome please write the init method please This interface defines.docxcan someome please write the init method please This interface defines.docx
can someome please write the init method please This interface defines.docx
hamblymarta
 

Mehr von hamblymarta (20)

Choose a piece of children's-adolescent media from any era and analyze.docx
Choose a piece of children's-adolescent media from any era and analyze.docxChoose a piece of children's-adolescent media from any era and analyze.docx
Choose a piece of children's-adolescent media from any era and analyze.docx
 
Complete parts (a) and (b) below- The number of dogs per household in.docx
Complete parts (a) and (b) below- The number of dogs per household in.docxComplete parts (a) and (b) below- The number of dogs per household in.docx
Complete parts (a) and (b) below- The number of dogs per household in.docx
 
Comider a pond or tiver adfacent to a higpo iawn in Arrica- The water.docx
Comider a pond or tiver adfacent to a higpo iawn in Arrica- The water.docxComider a pond or tiver adfacent to a higpo iawn in Arrica- The water.docx
Comider a pond or tiver adfacent to a higpo iawn in Arrica- The water.docx
 
Combining estimates with projections of likely events such as turnover.docx
Combining estimates with projections of likely events such as turnover.docxCombining estimates with projections of likely events such as turnover.docx
Combining estimates with projections of likely events such as turnover.docx
 
Christine Danes has asked Dave and Mike to help her move into a new ap.docx
Christine Danes has asked Dave and Mike to help her move into a new ap.docxChristine Danes has asked Dave and Mike to help her move into a new ap.docx
Christine Danes has asked Dave and Mike to help her move into a new ap.docx
 
Cody is trying to explain to Sarah that one advantage enjoyed by plant.docx
Cody is trying to explain to Sarah that one advantage enjoyed by plant.docxCody is trying to explain to Sarah that one advantage enjoyed by plant.docx
Cody is trying to explain to Sarah that one advantage enjoyed by plant.docx
 
Combining Prehension and Propulsion- The Foot of Ardipithecus ramidus.docx
Combining Prehension and Propulsion- The Foot of Ardipithecus ramidus.docxCombining Prehension and Propulsion- The Foot of Ardipithecus ramidus.docx
Combining Prehension and Propulsion- The Foot of Ardipithecus ramidus.docx
 
Code needed in C++ Input and formatted output- Right-facing arrow Give.docx
Code needed in C++ Input and formatted output- Right-facing arrow Give.docxCode needed in C++ Input and formatted output- Right-facing arrow Give.docx
Code needed in C++ Input and formatted output- Right-facing arrow Give.docx
 
Class problem 5 -Animal personality- has been defined as consistent di.docx
Class problem 5 -Animal personality- has been defined as consistent di.docxClass problem 5 -Animal personality- has been defined as consistent di.docx
Class problem 5 -Animal personality- has been defined as consistent di.docx
 
Class Discussion - Guest Speaker - Laura Sonderup Q1- From your exper.docx
Class Discussion - Guest Speaker - Laura Sonderup Q1-  From your exper.docxClass Discussion - Guest Speaker - Laura Sonderup Q1-  From your exper.docx
Class Discussion - Guest Speaker - Laura Sonderup Q1- From your exper.docx
 
Choose all that apply- Which of the following proteins would have an E.docx
Choose all that apply- Which of the following proteins would have an E.docxChoose all that apply- Which of the following proteins would have an E.docx
Choose all that apply- Which of the following proteins would have an E.docx
 
Choose all that apply- Which of the following is something that all ce.docx
Choose all that apply- Which of the following is something that all ce.docxChoose all that apply- Which of the following is something that all ce.docx
Choose all that apply- Which of the following is something that all ce.docx
 
Choose every statement that is true about the cytoplasm- Cytoplasm can.docx
Choose every statement that is true about the cytoplasm- Cytoplasm can.docxChoose every statement that is true about the cytoplasm- Cytoplasm can.docx
Choose every statement that is true about the cytoplasm- Cytoplasm can.docx
 
Case Study- Data-Driven Transformation of Springfield's Police Force S.docx
Case Study- Data-Driven Transformation of Springfield's Police Force S.docxCase Study- Data-Driven Transformation of Springfield's Police Force S.docx
Case Study- Data-Driven Transformation of Springfield's Police Force S.docx
 
Charles Darwin used many different aspects of the natural world as evi.docx
Charles Darwin used many different aspects of the natural world as evi.docxCharles Darwin used many different aspects of the natural world as evi.docx
Charles Darwin used many different aspects of the natural world as evi.docx
 
Chapter 2 notes various problems in the use of ratios and metrics- Whi.docx
Chapter 2 notes various problems in the use of ratios and metrics- Whi.docxChapter 2 notes various problems in the use of ratios and metrics- Whi.docx
Chapter 2 notes various problems in the use of ratios and metrics- Whi.docx
 
Case -#2- Royal Bank of Canada v- Head West Energy Inc-- 2007 ABQB 154.docx
Case -#2- Royal Bank of Canada v- Head West Energy Inc-- 2007 ABQB 154.docxCase -#2- Royal Bank of Canada v- Head West Energy Inc-- 2007 ABQB 154.docx
Case -#2- Royal Bank of Canada v- Head West Energy Inc-- 2007 ABQB 154.docx
 
care plannursing diagnose risk for evidenced by prostatis nursing dia.docx
care plannursing diagnose risk for evidenced by prostatis  nursing dia.docxcare plannursing diagnose risk for evidenced by prostatis  nursing dia.docx
care plannursing diagnose risk for evidenced by prostatis nursing dia.docx
 
Can you please help me answer these two multiple choice questions- Tha.docx
Can you please help me answer these two multiple choice questions- Tha.docxCan you please help me answer these two multiple choice questions- Tha.docx
Can you please help me answer these two multiple choice questions- Tha.docx
 
can someome please write the init method please This interface defines.docx
can someome please write the init method please This interface defines.docxcan someome please write the init method please This interface defines.docx
can someome please write the init method please This interface defines.docx
 

Kürzlich hochgeladen

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

How to specify referential integrity between customer and Rep tables-S.docx

  • 1. How to specify referential integrity between customer and Rep tables. Solution The purpose of using referential integrity is to prevent records that reference other records that do not exist. It also helps to keep references synchronized .Referential integrity is applied for a table relationship. Once enforced, Access rejects any operation that would violate referential integrity for that table relationship. Access rejects updates that change the target of a reference, and also deletions that remove the target of a reference. After referential integrity is applied, the following rules apply: A value cannot be entered in the foreign key field of a related table if that value doesn't exist in the primary key field of the primary table. If it happens, then records in the second table refer to records in the primary table which do not exist. They are called orphan records. Deleting a record from a primary table cannot happen if matching records exist in a related table, i.e deletion a record from the Customer table if there are orders assigned to that record in the rep table cannot take place. Primary key value cannot be changed in the primary table, if doing so would create orphan records. Example, you cannot change a customer number in the customers table if there are line items assigned to that customer in the rep table . The database enforces the rules of this relationship to maintain referential integrity by using a foreign key which allows declaring that an index in one table is related to an index in another and allows you to place constraints on what may be done to the table containing the foreign key. Syntax FOREIGN KEY [index_name] (index_columns) REFERENCES tbl_name (index_columns) Example
  • 2. SQL> create table customer(cust_id varchar2(10) primary key, cust_name varchar2(20)); SQL> create table rep(no number(3), cust_id varchar2(10) references customer(cust_id));