Академический Документы
Профессиональный Документы
Культура Документы
Relational databases
O Relational databases are the most
common form of databases. O Relational information systems are designed to avoid common issues arising in Flat-file databases:
O Redundancy O Inefficiency O Update anomalies O Data loss
Relational tables
O A relational database is made up of a
group of named tables. O Each data entry in a cell is called an . O Each column of data is referred to as a . O Each row of data in the table is a or .
each row, we can set one (or more) of the fields as . O A key field(s) cannot have duplicate values. E.g. idNo could be a key field as long as there are no two numbers the same. O Multiple keys can be used if the value of the combined fields is what makes it unique. O E.g. student/subject/semester achieves a grade.
Procedure (CSDP), used in conjunction with the Optimal Normal Form (ONF) will always create relational tables.
More terminology
= basic objects in UoD (can be either physical or abstract) = the type of object eg. Code, name etc = What each entity does. Eg. Sam studies IPT studies is the role = the number of entities involved in a fact type = predicate(entity) eg: Olivia is_male = predicate(entity,entity) eg: Olivia has_gender Male = predicate(entity,entity,entity) eg: Olivia obtained VHA in IPT
relationships between entities in the most atomic way possible. This means that they cannot be reduced further without loss of the relationship. e.g. O Bob studies IPT is an elementary fact . O Bob studies loses some of the relationship between the student and the subject.
Elementary Sentences
O An elementary sentence is a formal
statement of an elementary fact. O It breaks the fact into its component parts: O Entity(ies) the object in the fact O Role what the object does
O
O O
Primary state In the example, Bob studies IPT, there are 2 entities: Bob and IPT. Bob is a Student. Bob represents the Student Name IPT is a Subject. IPT represents the Subject Name.
1. The Object type (Student) 2. The Reference (Name) 3. Example (Bob) O Eg. Bob now becomes: Student(name) Bob and IPT: Subject(name) IPT
Bob
Put it all together and Bob studies IPT becomes: Student(name) Bob studies/is studied by Subject(name) IPT
Entity
Role
Entity
Another format:
Student (name) Bob studies/is studied by Subject (name) IPT
Entity Role Entity
This format allows for an easier identification of the entities and roles, but takes more space. My preference is for one line, however, you may use either.
Just Remember!
O Write your facts out first
O Ensure that they are elementary O Identify entities (underline the objects) O Write each fact as an Elementary
Sentence
relationships!
introduce here, but some include uniqueness constraints, mandatory constraints, frequency constraints and so on. O We will look at these in greater depth later in the CSDP.
it simply becomes a case of replacing the entities with ovals and the roles with boxes. O Student(name) Bob studies/is studied by Subject(name) IPT
Student (name) Subject (name)
studies
is_studied_by
1. Each entity must play at least 1 role. 2. Each role must be played by at least 1 entity 3. Each role must be played by at most 1 entity O Finally, there should only be 1 diagram with all areas connected through others.
e
Object1 Object3
1203
J. Seinfeld
11 PCC
11IPTA
IPT
Its all school Convert to elementary sentences B. Jones ** O Student(id) 1202 has/is for Name
O Student(id) 1202 is in/has PC (code) 11 PCA O Student(id) 1202 has/is for Gender(code) M O Student(id) 1202 studies/is studied by
Student (id)
has
is for
Gender (code)
Student (id)
studies
is studied by
Subject (id)
Subject (id)
is called
is for
Name
Student (id)
has
is for
Gender (code)
Student (id)
studies
is studied by
Subject (id)
Subject (id)
is called
is for
Name
Like entities have been combined into 1. All the entity/role relationships also come off the one entity
Gender (code) is for has
is for
has
is for
Name
A sample
O Pg 171
Question 8: Go from start (as is) through to Conceptual Schema create elementary facts, elementary sentences, conceptual schema fragments, whole conceptual schema.
Like entities have been combined into 1. All the entity/role relationships also come off the one entity
Item(id) 1010 is called/is for Item(name) Backpack Item(id) 1010 has/is for Cost($) 15.95 Item(id) 1010 has/is for RRP($) 39.95 Item(id) 1010 has/is for Profit($) 24.00
The CSD
Profit can worked out by RRP Cost This means it can be derived
Uniqueness Constraints
O Uniqueness constraints simply state how
O
O O
O
O
many times an entity can play a role. They are displayed by drawing a line/arrow above the role which is unique. There are four types of uniqueness constraints: 1-many many-1 (reversal of 1:many) 1-1 many-many
ask the question: O How many times can this entity play this role? O How many times can the other entity play the role?
A 1-many constraint
O A 1 to many constraint indicates that an
entity play a role only 1 time but that the reverse role can be played many times. e.g: O Student(id)1203 has/is_for Gender(code)m O How many genders can a student have? 1 O How many students can a gender be for? many
Constraint is 1:many
Student (id)
has
is for
Gender (code)
1 to 1 Constraint
O Student(id) 1203 has Student(name) B.
Constraint is 1:1
Student (id)
has
has
Student (name)
many - many
O Student(id) 1203 studies Subject(code)
11ENGA
O How many subjects can a student study? O How many students are in a subject?
man y many
Constraint is many:many
Student (id)
studies
is studied by
Subject (code)
by Subject(code) 11 ENG O Student(name) Claudia achieves/is achieved by Grade(LOA) HA Or O Subject(code) 11 ENG scores/is score for Grade(LOA) HA
O No because we now dont know what the grade
was for. Claudia (for example) achieves a HA for English and a VHA for IPT which is which?
Ternary CSD:
Nested Relationships
O A nested relationship represents
O O O
the relationship between the combination of the Student and the Subject with the Grade. So, a Grade is dependant upon the Student-Subject combination. Elementary sentences: StudentSubject = [Student(name) studies/is studied by Subject(code)] StudentSubject scores/score for Grade(LOA)
Questions
O Pages 181 182
O Questions 1 and 4 O FINISH FOR HOMEWORK!!!!
Mandatory Constraints
O Mandatory constraints are used to show
when an entity must play a role. O It is shown on the CSD with a dot ( ) on the entity where the line linking it to the role meets it.
Entity Constraints
O An entity constraint is used to restrict the
type of data which is allowed to be stored for that entity. O E.g. Gender(code) would only need M or F to be stored. O These are shown by using { } next to the entity being restricted. O It can include simple values or a range.
Frequency Constraints
O Frequency constraints are used to show
how many times a role can be played. O Obviously, these can only be used on many roles as the uniqueness constraint states it can only be played once. O These are usually placed above or below the role with a line indicating which it applies to.
schema diagram into properly relational tables ready for creation in a database. O It has three steps: 1. Loop all the 1-m relationships based around a central entity 2. Loop all the m-m (and nested) relationships as individual tables 3. Create named tables and underline the unique entities.
With ONF: