Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Design & ER Diagrams

Similar presentations


Presentation on theme: "Database Design & ER Diagrams"— Presentation transcript:

1 Database Design & ER Diagrams
Basis Data 2

2 ER, Relational Model

3 Database Design The database design process can be divided into six steps. The ER model is most relevant to the first three steps. Requirements Analysis Conceptual Database Design Logical Database Design 1. what data is to be stored in the database, what applications must be built on top of it, and what operations are most frequent and subject to performance requirements 2. The information gathered in the requirements analysis step is used to develop a high-level description of the data to be stored in the database, along with the constraints known to hold over this data. This step is often carried out using the ER model The ER model is one of several high-level, or semantic, data models used in database design. The goal is to create a simple description of the data that closely matches how users and developers think of the data 3. We must choose a DBMS to implement our database design, and convert the conceptual database design into a database schema in the data model of the chosen DBMS. We will consider only relational DBMSs, and therefore, the task in the logical design step is to convert an ER schema into a relational database schema.

4 The remaining three steps of database design Schema Refinement
Physical Database Design Application and Security Design 4. The fourth step ill databa')e design is to analyze the collection of relations in our relational database schema to identify potential problems, and to refine it. In contrast to the requirements analysis and conceptual design steps, which are essentially subjective, schema refinement can be guided by some elegant and powerful theory. 5. In this step, we consider typical expected workloads that our database must support and further refine the database design to ensure that it meets desired performance criteria. This step may simply involve building indexes on some tables and clustering some tables, or it may involve a substantial redesign of parts of the database schema obtained from the earlier design steps.

5 Entities, Attributes, And Entity Sets
An entity is an object in the real world that is distinguishable from other objects It is often useful to identify a collection of similar entities. Such a collection is called an entity set An entity is described using a set of attributes. All entities in a given entity set have the same attributes; this is what we mean by similar. For each attribute associated with an entity set, we must identify a domain of possible values derived attribute can be obtained from other attributes or related entities Weak and Strong Entity is…

6 Relationships And Relationship Sets
A relationship is an association among two or more entities. Set of similar relationships is called relationship set. A relationship set can be thought of as a set of n-tuples: A relationship can also have descriptive attributes  used to record information about the relationship [Employee] -- <work> -- [department] | (since)  descriptive attribute As another example of an ER diagram, suppose that each department has offices in several locations and we want to record the locations at which each employee works. This relationship is ternary because we must record an association between an employee, a department, and a location.

7 ADDITIONAL FEATURES OF THE ER MODEL
Key Constraints

8 Additional Features Of The ER Model
Key Constraints  statement that a certain minimal subset of the fields of a relation is a unique identifier for a tuple A set of fields that uniquely identifies a tuple according to a key constraint is called a candidate key for the relation; we often abbreviate this to just key Sometimes the information stored in a relation is linked to the information stored in another relation that’s why we need Foreign Key. The foreign key in the referencing relation must match the primary key of the referenced relation, that is must have the same number of columns and compatible data types

9 Cardinality Constraints
Cardinality of relationship One to one One to many Many to many

10 Participation Constraints

11 Participation Constraints

12 Additional Features Of The ER Model
Weak Entities Class Hierarchies

13 Enhanced ER Models (EER)
Semantic modelling concepts (abstraction) Specialisation Generalisation Classification/Categorisation Aggregation First we need some new entity constructs. Superclass - an entity type that includes distinct subclasses that require to be represented in a data model. Subclass - an entity type that has a distinct role and is also a member of a superclass.

14 Specialisation This is the process of maximising the differences between members of an entity by identifying their distinguishing characteristics. Here we have shown that the manages relationship is only applicable to the Manager subclass, whereas the works_for relationship is applicable to all staff. It is possible to have subclasses of subclasses.

15 Generalisation Generalisation is the process of minimising the differences between entities by identifying common features. This is the identification of a generalised superclass from the original subclasses. This is the process of identifying the common attributes and relationships. For instance, taking: car(regno,colour,make,model,numSeats) motorbike(regno,colour,make,model,hasWindshield) And forming: vehicle(regno,colour,make,model,numSeats,hasWindshielf)

16

17

18 Categorisation ? Aggregation ?
Classification abstraction defines a class of objects with a common set of properties. It collects similar things into a class. Example: class month = {January, February, . . .}. January, February, etc., are members of class month. In other words, January, February, etc., are classified as month. The arc represents the relationship: IS_MEMBER_OF. Thus, we say January IS_MEMBER_OF class month. The E-R model cannot express relationships among relationships. The solution is to use aggregation. An abstraction through which relationships are treated as higher-level entities. For our example, we treat the relationship set work and the entity sets employee and project as a higher-level entity set called work.

19 Conceptual Design With The ER Model
Entity versus Attribute Entity versus Relationship Binary versus Ternary Relationships Aggregation versus Ternary Relationships

20 Integrity Constraints Over Relations
Key Constraints Which one is the primary key used in the table Foreign Key Constraints Which one is the foreign key to refer to another table General Constraints The domain in the attribute

21 Enforcing Integrity Constraints
Insert  if not exists in referenced table, reject the insertion Delete  can be one of the options: Delete all rows in referenced table Disallow deletion Set the primary key to the existing default row Set the primary key to null Update  same as previous

22 Enforcing Integrity Constraints
CREATE TABLE Enrolled ( studid CHAR(20) ,cid CHAR(20) , grade CHAR(10), PRIMARY KEY (studid, dd), FOREIGN KEY (studid) REFERENCES Students ON DELETE CASCADE ON UPDATE NO ACTION) CASCADE , if a Students row is deleted, all rows that refer to it are to be deleted as well ON DELETE SET DEFAULT set to default as defined in default value constraint

23 Logical Database Design: ER to Relational
Entity Sets to Tables Relationship Sets (without Constraints) to Tables Translating Relationship Sets with Key Constraints Translating Relationship Sets with Participation Constraints Translating Weak Entity Sets Translating Class Hierarchies Translating ER Diagrams with Aggregation

24 Normalization

25 Schema Refinement Why do we need decomposition?
What is Functional Dependency (FD)? Normal forms 1NF 2NF 3NF Boyce-Codd (BCNF) 4NF 5NF


Download ppt "Database Design & ER Diagrams"

Similar presentations


Ads by Google