Chapter 3
Chapter 3
Predicate logic
Set theory
- is a mathematical science that deals with sets, or groups of things, and is used as the basis
for data manipulation in the relational model.
- Example:
o set A contains three numbers: 16, 24, and 77. A(16, 24, 77).
o set B contains four numbers, 44, 77, 90, and 11. B(44, 77, 90, 11)
o conclude that the intersection of A and B yields a result set with a single number,
77. as A > B 5 77
Based on these concepts, the relational model has three well-defined components:
2. A set of integrity rules to enforce that the data is consistent and remains consistent over time
- allowing the designer to focus on the logical representation of the data and its relationships,
rather than on the physical storage details.
- enables you to view data logically rather than physically
o it serves as a reminder of the simple file concept of data storage.
- logical view of the relational database is facilitated by the creation of data relationships
based on a logical construct known as a relation
- Logical simplicity tends to yield simple and effective database design methodologies
Table
Note:
Although various DBMSs can support different data types, most support at least the following:
A. Numeric. You can use numeric data to perform meaningful arithmetic procedures.
- For example, in Figure 3.1, STU_HRS and STU_GPA are numeric attributes.
B. Character. Character data, also known as text data or string data, can contain any character or
symbol not intended for mathematical manipulation.
- In Figure 3.1, STU_CLASS and STU_PHONE are examples of character attributes.
C. Date. Date attributes contain calendar dates stored in a special format known as the Julian date
format.
- In Figure 3.1, STU_DOB is a date attribute.
D. Logical. Logical data can only have true or false (yes or no) values.
- In Figure 3.1, the STU_TRANSFER attribute uses a logical data format.
5. The column’s range of permissible values is known as its domain. Because the STU_GPA values
are limited to the range 0–4, inclusive, the domain is [0,4]
7. Each table must have a primary key. In general terms, the primary key (PK) is an attribute or
combination of attributes that uniquely identifies any given row. In this case, STU_NUM (the
student number) is the primary key.
Key
- important because they are used to ensure that each row in a table is uniquely identifiable
- used to establish relationships among tables and to ensure the integrity of the data
- consists of one or more attributes that determine other attributes.
- attribute or group of attributes that can determine the values of other attributes.
- keys are determinants in functional dependencies
- Examplle:
o an invoice number identifies all of the invoice attributes, such as the invoice date
and the customer name
Determination
- is the state in which knowing the value of one attribute makes it possible to determine the
value of another
- the statement “A determines B” indicates that knowing the value of attribute A means that
the value of attribute B can be looked up
- Example:
o revenue 2 cost 5 profit. This is a form of determination, because if you are given the
revenue and the cost, you can determine the profit.
- Determination in a database environment, however, is not normally based on a formula but
on the relationships among the attributes.
- Example
o given a value for STU_NUM, then you can determine the value for STU_LNAME
because one and only one value of STU_LNAME is associated with any given value of
STU_NUM
functional dependence
- means that the value of one or more attributes determines the value of one or more other
attributes.
- determinant or the key.
o the attribute whose value determines another
- dependent
o attribute whose value is determined by the other attribute
- can involve a determinant that comprises more than one attribute and multiple dependent
attributes
- Example:
o STU_NUM is the determinant and STU_LNAME is the dependent. STU_NUM
functionally determines STU_LNAME, and STU_LNAME is functionally dependent on
STU_NUM
o STU_NUM → (STU_LNAME, STU_FNAME, STU_GPA) and (STU_FNAME, STU_LNAME,
STU_INIT, STU_PHONE) → (STU_DOB, STU_HRS, STU_GPA
- used to refer to functional dependencies in which the entire collection of attributes in the
determinant is necessary for the relationship.
Types of Key
1. Composite key
- is a key that is composed of more than one attribute
2. superkey
- key that can uniquely identify any row in the table.
- functionally determines every attribute in the row.
Example:
Example:
Note:
1. primary keys are candidate keys, but not all candidate keys are chosen to be the primary key
2. All candidate keys are superkeys, but not all superkeys are candidate keys.
Entity integrity
- is the condition in which each row (entity instance) in the table has its own known, unique
identity
(1) all of the values in the primary key must be unique and
Null
- the absence of any data value, and it is never allowed in any part of the primary key
- roblematic in the relational model.
- a table that contains a null is not properly a relational table at all
- however, some nulls cannot be reasonably avoided.
- Example:
o not all students have a middle initial.
- GR: nulls should be avoided as much as reasonably possible
- a null could represent any of the following:
• An unknown attribute value
• A known, but missing, attribute value
• A “not applicable” condition
- can create problems when functions such as COUNT, AVERAGE, and SUM
- the primary key of one table that has been placed into another table to create a common
attribute
Note:
1. , the primary key of VENDOR, VEND_CODE, was placed in the PRODUCT table
2. VEND_CODE is a foreign key in PRODUCT
referential integrity
- the condition in which every reference to an entity instance by another entity instance is
valid.
a secondary key
- is defined as a key that is used strictly for data retrieval purposes and does not require a
functional dependence
- Example:
o CUSTOMER table in which the customer number is the primary key. Do you think
that most customers will remember their numbers? Data retrieval for a customer is
easier when the customer’s last name and phone number are used.
o In that case, the primary key is the customer number; the secondary key is the
combination of the customer’s last name and phone number