Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.

Similar presentations


Presentation on theme: "CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs."— Presentation transcript:

1 CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs

2 Relational model Enables programmer to view data logically rather than physically Relational Model

3  A database is a collection of information that is organized so that it can easily be accessed, managed, and updated.  In one view, databases can be classified according to types of content: bibliographic, full-text, numeric, and images. What is Database?

4  Table: two-dimensional structure composed of rows and columns  Components of database table are :  Record (tuple) - is a sequence of attributes i.e. a row in the relation table.  Attribute (field) - is a named column in the relation table.  Domain - The domain of an attribute defines the set of values which can apply to that attribute.  Degree - The degree of a relation refers to the number of attributes in each tuple.  Cardinality - This refers to the number of tuples in the relation Components of Database Table

5

6

7  Relation Schema: relation name + attribute names + domain  Relation name  Attribute name  Domains Characteristic of Relation Scheme

8  Consists of one or more attributes that determine other attributes. Keys  Primary Key - Primary key (PK) is an attribute (or a combination of attributes) that uniquely identifies any given entity (row)  Superkey - Any key that uniquely identifies each row  Candidate key - A superkey without redundancies  Composite key - Composed of more than one attribute  Foreign key – a field in a relational table that matches the primary key column of another table. The foreign key can be used to cross-reference tables

9

10

11  Entity Integrity  Referential Integrity - FK contains a value that refers to an existing valid tuple (row) in another relation Integrity Rules

12

13 Relational Model Relationship

14 One entity related to another of the same entity type Entities of two different types related to each other Entities of three different types related to each other

15  Each entity in the relationship will have exactly one related entity One to Many Relationship

16

17  Entities on both sides of the relationship can have many related entities on the other side Many to Many Relationship

18

19 Converting the M:N relationship into TWO 1:M relationships Foreign keys reference the primary keys in the other tables of which it has a relationship with The database designer has 2 main options to define a composite table’s primary key: either use the combination of those foreign keys or create a new primary key.

20  Self-referencing relationships are a special case of a normal table relationship.  The only difference is that in this case, there is only one table involved and it is on both sides of the relationship.  Example :  One common example is an Employees table that contains information about the supervisor of each employee. Each supervisor is also an employee and has his or her own supervisor. In this case, there is a one- to-many self-referencing relationship, as each employee has one supervisor but each supervisor may have more than one employee. Self Referencing Relationship

21

22  Relational algebra  Defines theoretical way of manipulating table contents using relational operators  Use of relational algebra operators on existing tables (relations) produces new relations Relational Database Operators Restrict (select)ProjectJoin (outer, inner)Cross Product

23  Yields values for all rows found in a table  Can be used to list either all row values or it can yield only those row values that match a specified criterion  Yields a horizontal subset of a table Select

24

25   Yields all values for selected attributes  Yields a vertical subset of a table Project

26

27  Allows information to be combined from two or more tables  Real power behind the relational database, allowing the use of independent tables linked by common attributes Join

28

29  Outer join:  Matched pairs are retained and any unmatched values in other table are left null  In outer join for tables CUSTOMER and AGENT, two scenarios are possible:  Left outer join  Yields all rows in CUSTOMER table, including those that do not have a matching value in the AGENT table  Right outer join  Yields all rows in AGENT table, including those that do not have matching values in the CUSTOMER table

30

31

32  Inner Join  An inner join (sometimes called a simple join) is a join of two or more tables that returns only those rows that satisfy the join condition.  Traditional inner joins look for rows that match rows in the other table(s), i.e. to join two tables based on values in one table being equal to values in another table  Also known as equality join, equijoin or natural join  Returns results only if records exist in both tables

33

34  Cross Product


Download ppt "CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs."

Similar presentations


Ads by Google