Cardinality
March-2005 Cardinality | 2.15.01
Objectives
• The participants will be able to :
– Define cardinality of Foreign Key Relationships.
– Discuss about the different Foreign Key Field
Types.
March-2005 Cardinality | 2.15.01 2
Cardinality
March-2005 Cardinality | 2.15.01 3
nn :: mmnn :: mm
1
C
1
C
N
CN
Foreign Key Field Type
• Check Table: Students
• Foreign Key Table: Course Enrolment
March-2005 Cardinality | 2.15.01 4
Course Enrolment
STUDENT_ID
?
Foreign Key Type: Key Fields or Key
Field Candidates
March-2005 Cardinality | 2.15.01 5
Faculty Course
Foreign Key Type: Key Fields of a Text
Table
March-2005 Cardinality | 2.15.01 6
T005
(Country Codes)
(T002)
(Language Codes)
T005T
(Country descriptions)
Foreign Key Type: Non-Key Field
Candidates
March-2005 Cardinality | 2.15.01 7
Course
Professor
Demonstration
•Creation of few custom tables and establishing
foreign key relationship between them with
Cardinality specified.
March-2005 Cardinality | 2.15.01 8
Practice
•Creation of few custom tables and establishing
foreign key relationship between them with
Cardinality specified.
March-2005 Cardinality | 2.15.01 9
Summary
•When creating foreign key relationships, you
should always specify the cardinality of that
relationship.
•In addition to specifying the cardinality of a
foreign key relationship, you should also
specify the foreign key field type. The foreign
key field type indicates whether the foreign key
fields belong to the primary key (or a candidate
key) of the foreign key table.
March-2005 Cardinality | 2.15.01 10
Questions
• What is Cardinality ?
• What are the different Foreign key field
types ?
March-2005 Cardinality | 2.15.01 11

cardinality1

  • 1.
  • 2.
    Objectives • The participantswill be able to : – Define cardinality of Foreign Key Relationships. – Discuss about the different Foreign Key Field Types. March-2005 Cardinality | 2.15.01 2
  • 3.
    Cardinality March-2005 Cardinality |2.15.01 3 nn :: mmnn :: mm 1 C 1 C N CN
  • 4.
    Foreign Key FieldType • Check Table: Students • Foreign Key Table: Course Enrolment March-2005 Cardinality | 2.15.01 4 Course Enrolment STUDENT_ID ?
  • 5.
    Foreign Key Type:Key Fields or Key Field Candidates March-2005 Cardinality | 2.15.01 5 Faculty Course
  • 6.
    Foreign Key Type:Key Fields of a Text Table March-2005 Cardinality | 2.15.01 6 T005 (Country Codes) (T002) (Language Codes) T005T (Country descriptions)
  • 7.
    Foreign Key Type:Non-Key Field Candidates March-2005 Cardinality | 2.15.01 7 Course Professor
  • 8.
    Demonstration •Creation of fewcustom tables and establishing foreign key relationship between them with Cardinality specified. March-2005 Cardinality | 2.15.01 8
  • 9.
    Practice •Creation of fewcustom tables and establishing foreign key relationship between them with Cardinality specified. March-2005 Cardinality | 2.15.01 9
  • 10.
    Summary •When creating foreignkey relationships, you should always specify the cardinality of that relationship. •In addition to specifying the cardinality of a foreign key relationship, you should also specify the foreign key field type. The foreign key field type indicates whether the foreign key fields belong to the primary key (or a candidate key) of the foreign key table. March-2005 Cardinality | 2.15.01 10
  • 11.
    Questions • What isCardinality ? • What are the different Foreign key field types ? March-2005 Cardinality | 2.15.01 11

Editor's Notes

  • #4 When creating foreign key relationships, you should always specify the cardinality of that relationship. Here is a reminder of the possible values for each side of the n : m notation that SAP uses to specify cardinality. For a fuller review of cardinality, see Chapter 2. For the left side: n = 1 Each record in the foreign key table refers to exactly one record in the check table. n = C Each record in the foreign key table refers to zero or one records in the check table. For the right side: m = 1 Each record in the check table has exactly one dependent record. m = C Each record in the check table has a zero or one dependent records. m = N Each record in the check table has at least one dependent record. m = CN Each record in the check table has zero, one, or many dependent entities.
  • #5 In addition to specifying the cardinality of a foreign key relationship, you should also specify the foreign key field type. The foreign key field type indicates whether the foreign key fields belong to the primary key (or a candidate key) of the foreign key table. A candidate key is a field or combination of fields that uniquely identifies a record, but it is not necessarily the primary key of that table. (In some tables, there are multiple candidates for the primary key, but only one combination can be selected to be the primary key.) The cardinality and foreign key field type are together called the semantic attributes of the foreign key. Entry of these attributes is optional. However, it is good practice to maintain them, and it is necessary to maintain them if you wish to create certain types of aggregates. For example, help views can only be defined if the foreign key relationship has been specified as type: Key fields of a text table (this type is explained further on later pages.)
  • #6 Identifying fields of the foreign key table belong to the type: Key Fields or Key Field Candidates. Entries in these fields cannot be changed. This corresponds to the hierarchical or aggregating relationship. For example, it is not possible to change the faculty that offers a course without changing that course’s identity (Biology 101 does not remain the same if it is changed to Math 101).
  • #7 Key Fields of a Text Table are a special instance of Key Fields or Key Field Candidates. An additional condition in this case is that the dependent table is a language-dependent text table for the referenced table. The key of the text table is composed of the key of the referenced table and a language key. This corresponds to the aggregating relationship. For example, the table T005T contains language-dependent descriptions of country codes. The key fields of this table are client (MANDT), language key (SPRAS), and country key (LAND1). The foreign key type of the foreign key on the field LAND1 is Key Fields of a Text Table. This is because LAND1 and SPRAS (the language key) are both part of the primary key of T005T.
  • #8 Foreign key fields that do not belong to the identifying fields of the foreign key table are of the type: Non-key Field Candidates. Entries in these fields may be changed without changing the identity of the record in the foreign key table. This corresponds to the referential or conditional-referential relationship. For example, the primary professor responsible for overseeing a course may be changed without changing the identity of the course (Biology 101 is still Biology 101, no matter whether Professor Banning or Professor Cooper is in charge).