20
Chapter 3 Chapter 3

Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

  • View
    218

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

Chapter 3Chapter 3

Page 2: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

22

Chapter 3 - ObjectivesChapter 3 - Objectives• Terminology of relational model.Terminology of relational model.• How tables are used to represent data.How tables are used to represent data.• Connection between mathematical Connection between mathematical

relations and relations in the relational relations and relations in the relational model.model.

• Properties of database relations.Properties of database relations.• How to identify candidate, primary, and How to identify candidate, primary, and

foreign keys.foreign keys.• Meaning of entity integrity and Meaning of entity integrity and

referential integrity.referential integrity.• Purpose and advantages of views.Purpose and advantages of views.

Page 3: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

33

Relational Model Relational Model TerminologyTerminology• A relation is a table with columns and A relation is a table with columns and

rows.rows.– Only applies to logical structure of the Only applies to logical structure of the

database, not the physical structure.database, not the physical structure.

• Attribute is a named column of a Attribute is a named column of a relation.relation.

• Domain is the set of allowable values Domain is the set of allowable values for one or more attributes.for one or more attributes.

Page 4: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

44

Relational Model Relational Model TerminologyTerminology• Tuple is a row of a relation.Tuple is a row of a relation.

• Degree is the number of attributes in a relation.Degree is the number of attributes in a relation.

• Cardinality is the number of tuples in a relation.Cardinality is the number of tuples in a relation.

• Relational Database is a collection of Relational Database is a collection of normalized relations with distinct relation normalized relations with distinct relation names.names.

Page 5: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

55

Instances of Branch and Instances of Branch and Staff (part) RelationsStaff (part) Relations

Page 6: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

66

Examples of Attribute Examples of Attribute DomainsDomains

Page 7: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

77

Alternative Terminology Alternative Terminology for Relational Modelfor Relational Model

Page 8: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

88

Database RelationsDatabase Relations•Relation schemaRelation schema

– Named relation defined by a set of Named relation defined by a set of attribute and domain name pairs.attribute and domain name pairs.

•Relational database schemaRelational database schema– Set of relation schemas, each with Set of relation schemas, each with

a distinct name.a distinct name.

Page 9: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

99

Properties of RelationsProperties of Relations• Relation name is distinct from all other Relation name is distinct from all other

relation names in relational schema.relation names in relational schema.

• Each cell of relation contains exactly Each cell of relation contains exactly one atomic (single) value.one atomic (single) value.

• Each attribute has a distinct name.Each attribute has a distinct name.

• Values of an attribute are all from the Values of an attribute are all from the same domain.same domain.

Page 10: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1010

Properties of RelationsProperties of Relations•Each tuple is distinct; there are no Each tuple is distinct; there are no

duplicate tuples.duplicate tuples.

•Order of attributes has no Order of attributes has no significance.significance.

•Order of tuples has no Order of tuples has no significance, theoretically.significance, theoretically.

Page 11: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1111

Relational KeysRelational Keys•SuperkeySuperkey

– An attribute, or a set of attributes, that An attribute, or a set of attributes, that uniquely identifies a tuple within a relation.uniquely identifies a tuple within a relation.

•Candidate KeyCandidate Key– Superkey (K) such that no proper subset is a Superkey (K) such that no proper subset is a

superkey within the relation. superkey within the relation. – In each tuple of R, values of K uniquely In each tuple of R, values of K uniquely

identify that tuple (uniqueness).identify that tuple (uniqueness).– No proper subset of K has the uniqueness No proper subset of K has the uniqueness

property (irreducibility).property (irreducibility).

Page 12: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1212

Relational KeysRelational Keys•Primary KeyPrimary Key

• Candidate key selected to identify Candidate key selected to identify tuples uniquely within relation.tuples uniquely within relation.

• Alternate KeysAlternate Keys• Candidate keys that are not Candidate keys that are not

selected to be primary key. selected to be primary key.

• Foreign KeyForeign Key•Attribute, or set of attributes, Attribute, or set of attributes,

within one relation that matches within one relation that matches candidate key of some (possibly candidate key of some (possibly same) relation.same) relation.

Page 13: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1313

Relational IntegrityRelational Integrity•NullNull

– Represents value for an attribute Represents value for an attribute that is currently unknown or not that is currently unknown or not applicable for tuple.applicable for tuple.

– Deals with incomplete or Deals with incomplete or exceptional data.exceptional data.

– Represents the absence of a value Represents the absence of a value and is not the same as zero or and is not the same as zero or spaces, which are values.spaces, which are values.

Page 14: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1414

Relational IntegrityRelational Integrity• Entity IntegrityEntity Integrity

– In a base relation, no attribute of a In a base relation, no attribute of a primary key can be null.primary key can be null.

• Referential IntegrityReferential Integrity– If foreign key exists in a relation, If foreign key exists in a relation,

either foreign key value must match a either foreign key value must match a candidate key value of some tuple in candidate key value of some tuple in its home relation or foreign key value its home relation or foreign key value must be wholly null.must be wholly null.

Page 15: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1515

Relational IntegrityRelational Integrity•Enterprise ConstraintsEnterprise Constraints

– Additional rules specified by Additional rules specified by users or database users or database administrators.administrators.

Page 16: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1616

ViewsViews

• Base RelationBase Relation– Named relation corresponding to an Named relation corresponding to an

entity in conceptual schema, whose entity in conceptual schema, whose tuples are physically stored in tuples are physically stored in database.database.

• ViewView– Dynamic result of one or more Dynamic result of one or more

relational operations operating on relational operations operating on base relations to produce another base relations to produce another relation. relation.

Page 17: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1717

ViewsViews• A virtual relation that does not necessarily A virtual relation that does not necessarily

actually exist in the database but is actually exist in the database but is produced upon request, at time of request.produced upon request, at time of request.

• Contents of a view are defined as a query Contents of a view are defined as a query on one or more base relations. on one or more base relations.

• Views are dynamic, meaning that changes Views are dynamic, meaning that changes made to base relations that affect view made to base relations that affect view attributes are immediately reflected in the attributes are immediately reflected in the view. view.

Page 18: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1818

Purpose of ViewsPurpose of Views• Provides powerful and flexible security Provides powerful and flexible security

mechanism by hiding parts of database mechanism by hiding parts of database from certain users. from certain users.

• Permits users to access data in a Permits users to access data in a customized way, so that same data can customized way, so that same data can be seen by different users in different be seen by different users in different ways, at same time.ways, at same time.

• Can simplify complex operations on base Can simplify complex operations on base relations. relations.

Page 19: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

1919

Updating ViewsUpdating Views•All updates to a base relation All updates to a base relation

should be immediately should be immediately reflected in all views that reflected in all views that reference that base relation. reference that base relation.

• If view is updated, underlying If view is updated, underlying base relation should reflect base relation should reflect change.change.

Page 20: Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables

2020

Updating ViewsUpdating Views• There are restrictions on types of There are restrictions on types of

modifications that can be made modifications that can be made through views:through views:

- - Updates are allowed if query involves a Updates are allowed if query involves a single base relation and contains a single base relation and contains a candidate key of base relation.candidate key of base relation.

- Updates are not allowed involving - Updates are not allowed involving multiple base relations.multiple base relations.

- Updates are not allowed involving - Updates are not allowed involving aggregation or grouping operations.aggregation or grouping operations.