• 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. • 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. • For example, an employee entity may have the attributes employee’s name, age, address, salary, and job and attribute values.
Fundamental of Database System 5
Types of Attributes • Simple attribute − Simple attributes are atomic values, which cannot be divided further. For example, a student's phone number is an atomic value of 10 digits. • Composite attribute − Composite attributes are made of more than one simple attribute. For example, a student's complete name may have first_name and last_name. • Derived attribute − Derived attributes are the attributes that do not exist in the physical database, but their values are derived from other attributes present in the database. For example, average_salary in a department should not be saved directly in the database, instead it can be derived. For another example, age can be derived from data_of_birth. Fundamental of Database System 6 Types of Attributes
single value. For example − Social_Security_Number. • Multi-value attribute − Multi-value attributes may contain more than one values. For example, a person can have more than one phone number, email_address, etc.
Fundamental of Database System 7
Entity Types entity sets and Key Attributes • A database usually contains groups of entities that are similar. • 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. • 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. Fundamental of Database System 8 • 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 9
• 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 10
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 11
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 Unique keys are classified as: may be the same for more than one row. composite key • Foreign key is an example Candidate key of non unique key primary key Surrogate key Fundamental of Database System 12 Unique key 1. Composite key:- is a unique key composed of two or more attributes and uniquely identify the row. 2. Candidate key:- it is called candidate because it has the potential to become the primary key. 3. Primary key:- is a Candidate key chosen to be the main key for the relation. 4. 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 13
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 14
Relationship • A Relationship represents an association between two or more entities. An example of a relationship would be: • - “EMPLOYEES” are Assigned to “TEAMS” • - “CUSTOMERS” Owns “PROJECTS” • - “TEAMS” works on “PROJECTS” • 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 15 • 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 16
• 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 17 a) ONE-TO-ONE: one tuple is associated with only one other tuple. – E.g. Building – Locatio 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 18
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 19
Fundamental of Database System 20 • 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 21
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 22 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 23 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 24
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 25 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 Represent the constraintFundamental of Database System in the data 26 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 27 • 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 28
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 29
-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 30
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 31
Fundamental of Database System 32 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 33 Fig: sample E-R model Fundamental of Database System 34