Presentation is loading. Please wait.

Presentation is loading. Please wait.

INSTRUCTOR: MRS T.G. ZHOU

Similar presentations


Presentation on theme: "INSTRUCTOR: MRS T.G. ZHOU"— Presentation transcript:

1 INSTRUCTOR: MRS T.G. ZHOU E-MAIL: gwanzurat@msu.ac.zw
HCS 206-MODELS OF DATABASE AND DATABASE DESIGN RELATIONAL DATA MODEL LECTURE NOTES INSTRUCTOR: MRS T.G. ZHOU

2 MAIN ASPECTS OF A RELATIONAL MODEL
The relational model can be considered as having three parts and these are covered in sequence below: 1. Structural: defines the core of the data and the relationships involved. The model structure is described in terms of relations, tuples, attributes ,schemas,keys and domains. 2. Manipulative: defines how the data in the model will beaccessed and manipulated. This concerns how relations in the model will be manipulated to produce other relations, which in turn provide the answer to some question posed by a user of the data. The manipulation is achieved though relational algebra or relational calculus. 3. Integrity Constraints: defines limits on the model. The data integrity portion of the relation model defines mechanisms for ensuring that stored data is valid. The integrity constraints include: entity integrity, referential integrity and semantic constraints which are used to enforce rules on a relational database.

3 STRUCTURAL ASPECT

4 ATTRIBUTE It is a characteristic of data
An attribute has to have a name so that one can refer to it and the name has to be as relevant as possible for that feature Eg for a person the attributes can be name, age, date of birth etc Informal terms used to refer to an attribute include column or field

5 DOMAIN Is defined as set of atomic values of the same type
A value is the smallest unit of data in the relational model An atomic value is one that non-decomposable i.e. there can only be one set of value for a given attribute e.g. a student has only one registration number(atomic) whilst they can have more than one contact number(non-atomic) An attribute always has a domain associated with it

6 Domain continued…. A domain has a name so we can make reference to it and a dimension The dimension is given by the number of values that a domain has

7 TUPLE Is an ordered set of values that describe data characteristics at one moment in time Informal terms used to refer to a tuple include a row or record

8 example

9 RELATIONS A relation, which is the most basic part of the data structure model, has two parts: relation heading and relation body: Relation Heading A relation heading is a fixed set of (attribute, domain) pairs Relation Body A relation body is a set of tuples (i.e., rows). A tuple (row) can be thought of as an instance of a relation

10 Properties of Relations
Relations have three important properties. Each relation has a name, a cardinality and a degree. These properties help us to further define and describe relations. The three properties introduced above are defined as follows:

11 Properties continued….
Name: The first property is that a relation has a name which identifies it Cardinality: The second property of a relation it its cardinality. This refers to the number of tuples in the relation Degree/ Arity: The third and final property of a relation is its degree. The degree of a relation refers to the number of attributes in each tuple.

12 EXAMPLE For the relation above, the relation heading is: { (ID, integer), (Name, string), (Dept, string) }. The number of these pairs is known as the relation degree, therefore, the relation above is a degree three relation. The tuple represented by ID of 1, is actually this set { (ID, 1), (Name, Smith), (Dept, Sales) }. The number of tuples is known as the relation cardinality. For the relation above, it has a cardinality of 2.

13 KEYS Keys are used to enforce rules and or constraints on database data and these constraints are essential for maintaining data consistency and correctness There are 3 types of keys: Candidate key; primary key and foreign key

14 Candidate keys Candidate Keys- is a unique identifier for the tuples of a relation hence it is sometimes called a unique key Every relation has at least one candidate key A relation CAR with the following attributes (State, Reg#, SerialNo, Make, Model, Year) The attributes Reg# and SerialNo are candidate keys

15 PRIMARY KEYS Is unique identifier of the relation tuples
It is a candidate key chosen to represent the relation and every relation has one primary key If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The primary key attributes are underlined

16 example

17 FOREIGN KEY Is an attribute in one relation R2 whose values are required to match those of the primary key of some relation R1 A foreign key and the corresponding primary key should be defined on the same underlying domain

18 example ItemID WarehouseID Qty A 1 10 2 5 B 30 C 60 WarehouseID
Warehouse Address 1 Street1 2 Street2

19 INTEGRITY ASPECT Data integrity can be achieved using integrity rules or constraints These rules are specified at the database schema level If a user attempts to execute an operation that would violate the constraint then the system must either reject the operation or in some complicated situations perform some compensating action

20 ENTITY INTEGRITY It states that no attribute participating in the primary key of a relation is allowed to accept null values This is so because database relations correspond to entities from the real world and by definition entities in the real world are distinguishable i.e they have a unique identification of some kind

21 REFERENTIAL INTEGRITY
It states that if a relation R2 includes a foreign key matching the primary key of another relation R1 then every value of the FK in R2 must either be equal to the value of the PK in some tuple of R1 or be wholly null

22 example Note the following points about foreign keys:
ItemID WarehouseID Qty A 1 10 2 5 B 30 C 60 Note the following points about foreign keys: A foreign key value can be NULL. This means that the related row in the foreign table is unknown or does not exist. If a foreign key value is not NULL, the related row in the foreign table must exist. Composite foreign keys cannot be NULL. This would make it impossible to uniquely identify the relate row in the foreign table WarehouseID Warehouse Address 1 Street1 2 Street2

23 SEMANTIC INTEGRITY It refers to the correctness of the meaning of the data E.g the street number attribute value must be positive because in the real world street numbers are positive


Download ppt "INSTRUCTOR: MRS T.G. ZHOU"

Similar presentations


Ads by Google