Database Systems
(SWEG2108)
Chapter –3 Database Design
Chapter 3 Outline
• Relational Integrity Rules
• Conceptual DB Design: ER Diagrams - Revision
• Next lesson: Mapping ERD to Relational Model
2
Relational Constraints/Integrity Rules
The different Relational Integrity Rules
• Domain Integrity
• No value of the attribute should be beyond the allowable limits
• Entity Integrity
• In a base relation, no attribute of a Primary Key can assume a value of NULL
• Referential Integrity
• If a Foreign Key exists in a relation, either the Foreign Key value
must match a Candidate Key value in its home relation or the Foreign Key value must be NULL
• Enterprise Integrity
• Additional rules specified by the users or database administrators of
a database are incorporated Database Design 5
Relational Constraints/Integrity Rules - Example
Table 1: Student Table 2: Student
Table 3: Employee
Key constraints
• Super Key:
• Set of attribute or attributes that uniquely identifies a tuple within a relation.
• A key which we just understand or think at the beginning and they can even be
every key in a table
• Candidate Key:
• It is minimal subset of super key
• If any proper subset of a super key is super key then that key cannot be
a candidate key.
• Primary keys:
• The candidate key chosen to uniquely identify each row of data in a table
• The DBA Picks any one of the candidate key to be the primary key
• The rest one of the candidate key become alternate keys
• Foreign key:
• Primary key of another table used to define relationship with another table and
is used to maintain integrity
Database Design 7
What is composite key?
Key constraint Example
• Possible combination of Super keys
• The following key are combinations of candidate keys
• REG_ID is the primary key
• SID and EMAIL become alternate keys Database Design 8
Student Table
Relational Views
There are two kinds of relation in relational database.
1. Base Relation(Named Relation)
– corresponding to an entity in the conceptual schema, whose tuples
are physically stored in the database.
2. View (Unnamed Relation)
– A View is the dynamic result of one or more relational operations
operating on the base relations to produce another virtual relation
that does not actually exist as presented.
– View is a virtually derived relation that does not necessarily exist in
the database but can be produced upon request by a particular user
at the time of request.
Database Design 9
Purpose of a view
Hides unnecessary information from users:
– since only part of the base relation (Some collection of
attributes, not necessarily all) are to be included in the
virtual table.
Provide powerful flexibility and security:
– since unnecessary information will be hidden from the
user there will be some sort of data security.
Provide customized view of the database for users:
– each user is going to be interfaced with his own
preferred data set and format by making use of the
Views.
Database Design 10
Purpose of a view
• Update on views derived from various relations is not
allowed since it may violate the integrity of the database.
• Since aggregation and summary results are computed
from a base relation and does not exist actually.
– Update on view with aggregation and summary is not
allowed.
Database Design 11
Schemas and Instances
• When a database is designed using a
Relational data model
– all the data is represented in a form of a table.
• In such definitions and representation
– there are two basic components of the database.
» Schemas
» Instances
Database Design 12
Schemas and Instances
Database Schema:
– specifies name of relation and the collection of the attributes
(specifically the Name of attributes).
– refer to a description of database or describes how data is to be
structured
– specified during database design
– should not be changed unless during maintenance
Schema Diagrams
– convention to display some aspect of a schema visually
Schema Construct
– refers to each object in the schema (e.g. STUDENT)
• E.g.: STUDENT (FName, LName, Id, Year, Dept, Sex)
Database Design 13
Schemas and Instances
Instances
– is the collection of data in the database at a particular point of time
(snap-shot).
– Also called State or Snap Shot or Extension of the database
– Refers to the actual data in the database at a specific point in time
– State of database is changed any time we add, delete or update an
item.
– Since Instance is actual data of database at some point in time,
changes rapidly
• To define a new database, we specify its database schema to
the DBMS (database is empty)
• database is initialized when we first load it with data
Database Design 14
Database design: has 3 levels
Database Design 16
Database design: Conceptual Design
Database Design 17
Entity Relationship Diagram (ERD)
Database Design 18
ERD…
Database Design 19
ERD Example
Database Design 20
ERD… Cardinality Constraints: 1:1, 1:m, N:M
Database Design 21
Note : Keep in mind that connecting links like those enclosed with stars will have different meaning.
Database Design 22
ERD… Cardinality Constraints: 1:1, 1:m, N:M
ERD … Participation constraints
Database Design 23
Class Exercise: ER Diagram
A simplified requirements of tiny college are as follows:
• A college contains many departments.
• Each department can offer any number of courses.
• Many instructors can work in a departments.
• An instructor can work only in one department.
• For each department there is a head.
• An instructor can be head of only one department.
• Each instructor can offer any number of courses.
• A course can be offered by only one instructor.
• A student can enroll for any number of courses.
• Each course can be enrolled any number of students.
• Construct ER diagram and describe any assumption you take.
• Show the min. and max. cardinalities.
• State the degree of relation ship between entities.
Answer : ER Diagram
Note : Keep in mind that connecting links like those enclosed with star are wrongly connected.
Home Work : ER Diagram
Answer: ER Diagram
Thank
you!

Chapter – 3 Database Design P-I.pdf

  • 1.
  • 2.
    Chapter 3 Outline •Relational Integrity Rules • Conceptual DB Design: ER Diagrams - Revision • Next lesson: Mapping ERD to Relational Model 2
  • 3.
    Relational Constraints/Integrity Rules Thedifferent Relational Integrity Rules • Domain Integrity • No value of the attribute should be beyond the allowable limits • Entity Integrity • In a base relation, no attribute of a Primary Key can assume a value of NULL • Referential Integrity • If a Foreign Key exists in a relation, either the Foreign Key value must match a Candidate Key value in its home relation or the Foreign Key value must be NULL • Enterprise Integrity • Additional rules specified by the users or database administrators of a database are incorporated Database Design 5
  • 4.
    Relational Constraints/Integrity Rules- Example Table 1: Student Table 2: Student Table 3: Employee
  • 5.
    Key constraints • SuperKey: • Set of attribute or attributes that uniquely identifies a tuple within a relation. • A key which we just understand or think at the beginning and they can even be every key in a table • Candidate Key: • It is minimal subset of super key • If any proper subset of a super key is super key then that key cannot be a candidate key. • Primary keys: • The candidate key chosen to uniquely identify each row of data in a table • The DBA Picks any one of the candidate key to be the primary key • The rest one of the candidate key become alternate keys • Foreign key: • Primary key of another table used to define relationship with another table and is used to maintain integrity Database Design 7 What is composite key?
  • 6.
    Key constraint Example •Possible combination of Super keys • The following key are combinations of candidate keys • REG_ID is the primary key • SID and EMAIL become alternate keys Database Design 8 Student Table
  • 7.
    Relational Views There aretwo kinds of relation in relational database. 1. Base Relation(Named Relation) – corresponding to an entity in the conceptual schema, whose tuples are physically stored in the database. 2. View (Unnamed Relation) – A View is the dynamic result of one or more relational operations operating on the base relations to produce another virtual relation that does not actually exist as presented. – View is a virtually derived relation that does not necessarily exist in the database but can be produced upon request by a particular user at the time of request. Database Design 9
  • 8.
    Purpose of aview Hides unnecessary information from users: – since only part of the base relation (Some collection of attributes, not necessarily all) are to be included in the virtual table. Provide powerful flexibility and security: – since unnecessary information will be hidden from the user there will be some sort of data security. Provide customized view of the database for users: – each user is going to be interfaced with his own preferred data set and format by making use of the Views. Database Design 10
  • 9.
    Purpose of aview • Update on views derived from various relations is not allowed since it may violate the integrity of the database. • Since aggregation and summary results are computed from a base relation and does not exist actually. – Update on view with aggregation and summary is not allowed. Database Design 11
  • 10.
    Schemas and Instances •When a database is designed using a Relational data model – all the data is represented in a form of a table. • In such definitions and representation – there are two basic components of the database. » Schemas » Instances Database Design 12
  • 11.
    Schemas and Instances DatabaseSchema: – specifies name of relation and the collection of the attributes (specifically the Name of attributes). – refer to a description of database or describes how data is to be structured – specified during database design – should not be changed unless during maintenance Schema Diagrams – convention to display some aspect of a schema visually Schema Construct – refers to each object in the schema (e.g. STUDENT) • E.g.: STUDENT (FName, LName, Id, Year, Dept, Sex) Database Design 13
  • 12.
    Schemas and Instances Instances –is the collection of data in the database at a particular point of time (snap-shot). – Also called State or Snap Shot or Extension of the database – Refers to the actual data in the database at a specific point in time – State of database is changed any time we add, delete or update an item. – Since Instance is actual data of database at some point in time, changes rapidly • To define a new database, we specify its database schema to the DBMS (database is empty) • database is initialized when we first load it with data Database Design 14
  • 13.
    Database design: has3 levels Database Design 16
  • 14.
    Database design: ConceptualDesign Database Design 17
  • 15.
    Entity Relationship Diagram(ERD) Database Design 18
  • 16.
  • 17.
  • 18.
    ERD… Cardinality Constraints:1:1, 1:m, N:M Database Design 21 Note : Keep in mind that connecting links like those enclosed with stars will have different meaning.
  • 19.
    Database Design 22 ERD…Cardinality Constraints: 1:1, 1:m, N:M
  • 20.
    ERD … Participationconstraints Database Design 23
  • 21.
    Class Exercise: ERDiagram A simplified requirements of tiny college are as follows: • A college contains many departments. • Each department can offer any number of courses. • Many instructors can work in a departments. • An instructor can work only in one department. • For each department there is a head. • An instructor can be head of only one department. • Each instructor can offer any number of courses. • A course can be offered by only one instructor. • A student can enroll for any number of courses. • Each course can be enrolled any number of students. • Construct ER diagram and describe any assumption you take. • Show the min. and max. cardinalities. • State the degree of relation ship between entities.
  • 22.
    Answer : ERDiagram Note : Keep in mind that connecting links like those enclosed with star are wrongly connected.
  • 23.
    Home Work :ER Diagram
  • 24.
  • 25.