Chapter 3 discusses database modeling, emphasizing the importance of conceptual modeling and the Entity-Relationship (ER) model for designing successful database applications. It covers key concepts such as entities, attributes, relationships, and various types of attributes, as well as the classification of entities and keys. The chapter also outlines the process of creating an ER model and the iterative nature of developing a conceptual model through user interaction and feedback.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
13 views
Chapter 3
Chapter 3 discusses database modeling, emphasizing the importance of conceptual modeling and the Entity-Relationship (ER) model for designing successful database applications. It covers key concepts such as entities, attributes, relationships, and various types of attributes, as well as the classification of entities and keys. The chapter also outlines the process of creating an ER model and the iterative nature of developing a conceptual model through user interaction and feedback.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44
Chapter 3
Database Modeling
Fundamental of Database System 1
• Database modeling :designing successful database application where database application refers to specific database like Company database or University database. • Conceptual modeling is an important phase in designing a successful database application. • The Entity-Relationship (ER) model, is a popular high-level conceptual data model for designing database applications. • This model and its variations are frequently used for the conceptual design of database applications, and many database design tools employ its concepts. Fundamental of Database System 2 • E/R modeling is based on the concept of Entities, attributes and relationships. • Creating an Entity-Relationship Model involves: 1. Identify entities 2. Identify entity attributes and primary keys 3. Specify relationships
Fundamental of Database System 3
Entities and Their Attributes • The basic object that the ER model represents is an entity, which is a "thing" in the real world with an independent existence. • Entities are specific objects or things in the mini-world that are represented in the database. • An entity may be an object with a physical existence—a particular person, car, house, or employee—or it may be an object with a conceptual existence—a company, a job, or a university course. • Each entity has attributes—the particular properties that describe it. For example, an employee entity may be described by the employee’s name, age, address, salary, and job. Fundamental of Database System 4 • A particular entity will have a value for each of its attributes. • The attribute values that describe each entity become a major part of the data stored in the database. – A specific entity will have a value for each of its attributes. For example a specific employee entity may have Name='John Smith', SSN='123456789', Address ='731, Fondren, Houston, TX', Sex='M', BirthDate='09-JAN-55‘ – Each attribute has a value set (or data type) associated with it – e.g. integer, string, subrange, enumerated type, …
Fundamental of Database System 5
Types of Attributes
1. Simple (atomic) Vs Composite attributes
• Simple : contains a single value (not divided into sub parts) E.g. Age, gender • Composite: Divided into sub parts (composed of other attributes) E.g. Address (House#, Street, City, State, ZipCode, Country) Name (First Name, Middle Name, Last Name). 2. Single-valued Vs multi-valued attributes Single-valued : have only single value(the value may change but has only one value at one time) E.g. Name, Sex, Id. No. color_of_eyes Fundamental of Database System 6 Multi-valued – An entity may have multiple values for that attribute. For example, Color of a CAR or PreviousDegrees of a STUDENT. Denoted as {Color} or {PreviousDegrees}. E.g. Address, dependent-name – Person may have several college degrees 3. Stored vs. Derived Attribute Stored : not possible to derive or compute. E.g. Name, Address Derived: The value may be derived (computed) from the values of other attributes. – E.g. Age (current year – year of birth) – Length of employment (current date- start date) – Profit (earning-cost) – G.P.A (grade point/credit hours) Fundamental of Database System 7 4.Null Values – NULL applies to attributes which are not applicable or which do not have values. – You may enter the value NA (meaning not applicable) – Value of a key attribute can not be null.
Fundamental of Database System 8
Entity Types , entity sets and Key Attributes • A database usually contains groups of entities that are similar. • An entity type defines a collection (or set) of entities that have the same attributes. • Each entity type in the database is described by its name and attributes. • For example, a company employing hundreds of employees may want to store similar information concerning each of the employees. • These employee entities share the same attributes, but each entity has its own value(s) for each attribute. Fundamental of Database System 9 • The collection of all entities of a particular entity type in the database at any point in time is called an entity set; the entity set is usually referred to using the same name as the entity type. • For example, EMPLOYEE refers to both a type of entity as well as the current set of all employee entities in the database.
Fundamental of Database System 10
• An entity set is a set consisting of the same type of entities that share same properties. Some specific examples of entities are EMPLOYEES, PROJECTS, CUSTOMERS … Then The “EMPLOYEES” entity set represents all the set of employees and the “Projects” entity set represents all the set of projects.
Fundamental of Database System 11
Con’t
Fundamental of Database System 12
Entities are classified as independent (Strong) or dependent (Weak). • A strong (independent) entity is one that does not rely on other entities for identification. • Entity types that do have a key attribute are sometimes called strong entity types. • A weak (dependent) entity is one that relies on other entities for identification. • Entity types that do not have key attributes of their own are called weak entity types An individual occurrence of an entity set is also known as an instance (object).
Fundamental of Database System 13
Key Attributes of an Entity Type • An important constraint on the entities of an entity type is the key or uniqueness constraint on attributes. • An entity type usually has an attribute whose values are distinct for each individual entity in the collection. • Such an attribute is called a key attribute, and its values can be used to identify each entity uniquely. • For example for the PERSON entity type, a typical key attribute is SocialSecurityNumber. • Keys – are attributes or set of attributes that can be used to uniquely identify an entity within the entity set. • A key in E/R model is represented by underlining the attributes belonging to the key • As described above keys are attributes or set of attributes that suffice to distinguish entities from each other. Fundamental of Database System 14 Fundamental of Database System 15 Keys Unique keys Non unique keys
• Data value is unique for • Data value may be shared
each row among several rows, key • So the key uniquely will identify set of rows specify a single row • The value of the column may be the same for more Unique keys are classified as: than one row. composite key • Foreign key is an example Candidate key of non unique key primary key Surrogate key Fundamental of Database System 16 Unique key • Super Key: an attribute or set of attributes that uniquely identifies a tuple within a relation. • Candidate key:- it is called candidate because it has the potential to become the primary key. A candidate key has two properties: – Uniqueness – Irreducibility • If a super key is having only one attribute, it is automatically a Candidate key. • If a candidate key consists of more than one attribute it is called Composite Key. • Composite key:- is a unique key composed of two or more attributes and uniquely identify the row. For example Title, year and StarName can be key for movie entity which can identify uniquely one movie from the other. Fundamental of Database System 17 Con’t Primary key:- is a Candidate key chosen to be the main key for the relation. Surrogate key:- is a unique key in which numeric value is added to serve as the primary key. Often used in place of a composite primary key.
Fundamental of Database System 18
Non unique key • Foreign key:- it s a primary key from table that is placed into another table for the purpose of linking the tables. • The key is called foreign key in the table that receives the key.
Fundamental of Database System 19
SQL Constraints
• Constraints are the rules enforced on data columns
on a table. These are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the database. • Constraints can either be column level or table level. Column level constraints are applied only to one column whereas, table level constraints are applied to the entire table.
Fundamental of Database System 20
Con’t • Following are some of the most commonly used constraints available in SQL: NOT NULL Constraint: Ensures that a column cannot have a NULL value. DEFAULT Constraint: Provides a default value for a column when none is specified. Default value - assumed value if no explicit value UNIQUE Constraint: Ensures that all the values in a column are different. PRIMARY Key: Uniquely identifies each row/record in a database table. FOREIGN Key: Uniquely identifies a row/record in any another database table. CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy certain conditions. INDEX: Used to create and retrieve data from the database very quickly.
Fundamental of Database System 21
Data Integrity • The following categories of data integrity exist with each RDBMS: Entity Integrity: There are no duplicate rows in a table. The entity integrity constraint states that in a base relation, no attribute of a Primary Key can assume a value of NULL . Domain Integrity: Enforces valid entries for a given column by restricting the type, the format, or the range of values. 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. Fundamental of Database System 22 Relationship • A Relationship represents an association between two or more entities. • Relationships are represented by DIAMOND shaped symbols • A relationship should be named by a word or phrase which explains its function An example of a relationship would be: - “EMPLOYEES” are Assigned to “TEAMS” - “CUSTOMERS” Owns “PROJECTS” - “TEAMS” works on “PROJECTS” - Strong Relationship is a relationship between two strong Entities Fundamental of Database System 23 Con’t
Strong Relationship • Weak Relationship is a relationship between Weak and Strong Entities Weak relationship
• A Relationship Set is then a set consisting same types of
relationships. The entities involved in the relationship are known as participating entities and the function the entity plays in a relationship is called the entity’s role.
Fundamental of Database System 24
• Example: In the Assigned relationship “EMPLOYEES” and “TEAMS” entity sets are the participating entity sets; and the “EMPLOYEES” entity has a role as a “Programmer” or “Team Leader” in the relationship. • Relationships are classified in terms of degree, connectivity, cardinality, and existence. • Degree: The degree of a relationship is the number of entities associated with the relationship. • The n-ary (multi-way) relationship is the general form for degree n. Special cases are the binary, and ternary, where the degree is 2, and 3, respectively.
Fundamental of Database System 25
• Connectivity: The connectivity of a relationship describes the mapping of associated entity instances in the relationship. • The values of connectivity are “one” or “many”. • Cardinality: The cardinality of a relationship is the actual number of related occurrences for each of the two entities. • The basic types of connectivity for relations are: a) one-to-one b) one-to-many c) many-to -one d) and many-to-many. Fundamental of Database System 26 a) ONE-TO-ONE: one tuple is associated with only one other tuple. – E.g. Building – Location as a single building will be located in a single location and as a single location will only accommodate a single Building. b) ONE-TO-MANY, one tupelo can be associated with many other tuples, but not the reverse. – E.g. Department-Student as one department can have multiple students. c) MANY-TO-ONE, many tuples are associated with one tuple but not the reverse. – E.g. Employee – Department: as many employees belong to a single department.
Fundamental of Database System 27
d)MANY-TO-MANY: one tuple is associated with many other tuples and from the other side, with a different role name one tuple will be associated with many tuples – E.g. Student – Course as a student can take many courses and a single course can be attended by many students.
Fundamental of Database System 28
Fundamental of Database System 29 • Existence: denotes whether the existence of an entity instance is dependent upon the existence of another, related, entity instance. • The existence of an entity in a relationship is defined as either mandatory or optional.
Fundamental of Database System 30
Cardinality Limits of a Relationship The credential limit of a relationship is labeled as: • - 0..* or 0..∞ indicating zero or more participation of the entity in the relationship. • - 1..* or 1..∞ indicating one or more participation of the entity in the relationship. • - 0..1 indicating zero or one participation of the entity in the relationship. • - 1..1 indicating exactly one participation of the entity in the relationship.
Fundamental of Database System 31
Database Design • The Three levels of Database Design Conceptual design Logical design Physical design Physical Database Design Physical design is the process of producing a description of the implementation of the database on secondary storage. defines specific storage or access methods used by database. Describes the storage structures and access methods used to achieve efficient access to the data. Includes estimate of storage space
Fundamental of Database System 32
Logical Database Design • Logical design is the process of constructing a model of the information used in an enterprise based on a specific data model (e.g. relational, hierarchical or network or object), but independent of a particular DBMS and other physical considerations. • Normalization process • Discover new entities • Revise attributes
Fundamental of Database System 33
Conceptual Database Design • Conceptual design revolves around discovering and analyzing and organizing organizational and user data requirements • The important activities are to identify – Entities – Attributes – Relationships – Constraints • And based on these components develop the ER model using ER diagrams Fundamental of Database System 34 The Entity Relationship (E-R) Model • The Entity Relationship (E/R) data model is a diagrammatical data model. • Entity-Relationship modeling is used to represent conceptual view of the database • The main components of ER Modeling are: o Entities Corresponds to entire table, not row Represented by Rectangle o Attributes Represents the property used to describe an entity or a relationship Represented by Oval o Relationships Represents the association that exist between entities Represented by Diamond o Constraints Fundamental of Database System 35 Developing an E-R Diagram • Designing conceptual model for the database is not a one linear process but an iterative activity where the design is refined again and again. • To identify the entities, attributes, relationships, and constraints on the data, there are different set of methods used during the analysis phase. • These include information gathered by… Interviewing end users individually and in a group Questionnaire survey Direct observation Examining different documents Fundamental of Database System 36 • The basic E-R model is graphically depicted and presented for review. • The process is repeated until the end users and designers agree that the E-R diagram is a fair representation of the organization’s activities and functions. • Check for Redundant Relationships in the ER Diagram. • Relationships between entities indicate access from one entity to another - it is therefore possible to access one entity occurrence from another entity occurrence even if there are other entities and relationships that separate them - this is often referred to as Navigation' of the ER diagram. • The last phase in ER modeling is validating an ER Model against requirement of the user. Fundamental of Database System 37 Graphical Representations in ER Diagramming The elements of the E/R model are represented by: - Rectangles - for the Entity sets, - Ellipses - for the Attributes, - Diamonds - for the Relationships, - Lines - for the links between the attributes and the entity sets and between the entity sets and the relationships.
Fundamental of Database System 38
-Double border Rectangles - for the weak entity sets. - Double border Ellipses - for the multi-valued attributes. - Dashed border Ellipses - for the derived attributes. - Arrow Head Line - for the link between an entity set and a one-to-one or many-to-one relationship. - The arrow is headed to the one side entity set. - PRIMARY KEYS are underlined.
Fundamental of Database System 39
40 Fundamental of Database System Example 1 • Build an ER Diagram for the following information: Students • Have an Id, Name, Dept, Age, Gpa Courses • Have an Id, Name, Credit Hours Students • Enroll in courses and receive a grade
Fundamental of Database System 41
Fundamental of Database System 42 Example 2: build an E-R diagram given the following information. - “EMPLOYEES” are Assigned to “TEAMS” - “CUSTOMERS” Owns “PROJECTS” - “TEAMS” works on “PROJECTS” Employees • have : Empid, Bdate, Name, age and address Teams • Have: Name and description Customers • Have: customer Id ,name, address project • have: name, project id, Sdate, Ddate Fundamental of Database System 43 Fig: sample E-R model Fundamental of Database System 44