Presentation is loading. Please wait.

Presentation is loading. Please wait.

DATABASE MANAGEMENT SYSTEMS

Similar presentations


Presentation on theme: "DATABASE MANAGEMENT SYSTEMS"— Presentation transcript:

1 DATABASE MANAGEMENT SYSTEMS
Unit-2 Engineered for Tomorrow Presented by CSE, MVJCE

2 Database Design Conceptual design: (ER Model is used at this stage.)
Engineered for Tomorrow Database Design Conceptual design: (ER Model is used at this stage.) What are the entities and relationships in the enterprise? What information about these entities and relationships should we store in the database? What are the integrity constraints or business rules that hold? A database `schema’ in the ER Model can be represented pictorially (ER diagrams). Can map an ER diagram into a relational schema.

3 Modeling A database can be modeled as: a collection of entities,
Engineered for Tomorrow Modeling A database can be modeled as: a collection of entities, relationship among entities. An entity is an object that exists and is distinguishable from other objects. Example: specific person, company, event, plant Entities have attributes Example: people have names and addresses An entity set is a set of entities of the same type that share the same properties. Example: set of all persons, companies, trees, holidays

4 Engineered for Tomorrow
Attributes An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set. Domain – the set of permitted values for each attribute Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes Example: multivalued attribute: phone_numbers Derived attributes Can be computed from other attributes Example: age, given date_of_birth

5 Mapping Cardinality Constraints
Engineered for Tomorrow Mapping Cardinality Constraints Express the number of entities to which another entity can be associated via a relationship set. Most useful in describing binary relationship sets. For a binary relationship set the mapping cardinality must be one of the following types: One to one One to many Many to one Many to many

6 Mapping Cardinalities
Engineered for Tomorrow Mapping Cardinalities One to one One to many

7 Mapping Cardinalities
Engineered for Tomorrow Mapping Cardinalities Many to one Many to many

8 Engineered for Tomorrow
ER Model Basics Employees ssn name lot Entity: Real-world object distinguishable from other objects. An entity is described (in DB) using a set of attributes. Entity Set: A collection of similar entities. E.g., all employees. All entities in an entity set have the same set of attributes. (Until we consider ISA hierarchies, anyway!) Each entity set has a key. Each attribute has a domain.

9 ER Model Basics (Contd.)
Engineered for Tomorrow name ER Model Basics (Contd.) ssn lot since name dname ssn lot did budget Employees super-visor subordinate Employees Works_In Departments Reports_To Relationship: Association among two or more entities. E.g., Attishoo works in Pharmacy department. Relationship Set: Collection of similar relationships. An n-ary relationship set R relates n entity sets E1 ... En; each relationship in R involves entities e1 E1, ..., en En Same entity set could participate in different relationship sets, or in different “roles” in same set.

10 Engineered for Tomorrow
Relationship Sets A relationship is an association among several entities A relationship set is a mathematical relation among n  2 entities, each taken from entity sets {(e1, e2, … en) | e1  E1, e2  E2, …, en  En} where (e1, e2, …, en) is a relationship

11 Degree of a Relationship Set
Engineered for Tomorrow Degree of a Relationship Set Refers to number of entity sets that participate in a relationship set. Relationship sets that involve two entity sets are binary (or degree two). Generally, most relationship sets in a database system are binary. Relationship sets may involve more than two entity sets. CSC Data Structures/Algorithms

12 Degree of a Relationship Set
Engineered for Tomorrow Degree of a Relationship Set Example: Suppose employees of a bank may have jobs (responsibilities) at multiple branches, with different jobs at different branches. Then there is a ternary relationship set between entity sets employee, job, and branch Relationships between more than two entity sets are rare. Most relationships are binary.

13 Additional features of the ER model
Engineered for Tomorrow since Additional features of the ER model lot name ssn dname did Manages Key Constraints Employees Departments Consider Works_In: An employee can work in many departments; a dept can have many employees. In contrast, each dept has at most one manager, according to the key constraint on Manages. 1-to-1 Many-to-Many 1-to Many Many-to-1

14 Participation Constraints
Engineered for Tomorrow Participation Constraints Does every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every Departments entity must appear in an instance of the Manages relationship. since since name name dname dname ssn lot did did budget budget Employees Manages Departments Works_In since

15 Engineered for Tomorrow
Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. name cost ssn pname lot age Employees Policy Dependents

16 Engineered for Tomorrow
Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the existence of a identifying entity set it must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the weak entity set Identifying relationship depicted using a double diamond The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set. The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity set is existence dependent, plus the weak entity set’s discriminator.

17 Weak Entity Sets (Cont.)
Engineered for Tomorrow Weak Entity Sets (Cont.) We depict a weak entity set by double rectangles. We underline the discriminator of a weak entity set with a dashed line. payment_number – discriminator of the payment entity set Primary key for payment – (loan_number, payment_number)

18 Engineered for Tomorrow
Aggregation name ssn lot Used when we have to model a relationship involving (entitity sets and) a relationship set. Aggregation allows us to treat a relationship set as an entity set for purposes of participation in (other) relationships. Employees Monitors until started_on since dname pid pbudget did budget Projects Sponsors Departments Aggregation vs. ternary relationship: Monitors is a distinct relationship, with a descriptive attribute. Also, can say that each sponsorship is monitored by at most one employee.

19 Engineered for Tomorrow
Aggregation Consider the ternary relationship works_on, which we saw earlier Suppose we want to record managers for tasks performed by an employee at a branch

20 Engineered for Tomorrow
Aggregation (Cont.) Relationship sets works_on and manages represent overlapping information Every manages relationship corresponds to a works_on relationship However, some works_on relationships may not correspond to any manages relationships So we can’t discard the works_on relationship Eliminate this redundancy via aggregation Treat relationship as an abstract entity Allows relationships between relationships Abstraction of relationship into new entity

21 E-R Diagram With Aggregation
Engineered for Tomorrow E-R Diagram With Aggregation

22 Binary vs. Ternary Relationships
Engineered for Tomorrow Binary vs. Ternary Relationships name Employees ssn lot If each policy is owned by just 1 employee, and each dependent is tied to the covering policy, first diagram is inaccurate. What are the additional constraints in the 2nd diagram? pname age Covers Dependents Bad design Policies policyid cost name Employees ssn lot pname age Dependents Purchaser Beneficiary Better design policyid cost Policies

23 Binary vs. Ternary Relationships (Contd.)
Engineered for Tomorrow Binary vs. Ternary Relationships (Contd.) Previous example illustrated a case when two binary relationships were better than one ternary relationship. An example in the other direction: a ternary relation Contracts relates entity sets Parts, Departments and Suppliers, and has descriptive attribute qty. No combination of binary relationships is an adequate substitute: S “can-supply” P, D “needs” P, and D “deals-with” S does not imply that D has agreed to buy P from S. How do we record qty?

24 Summary of Conceptual Design
Engineered for Tomorrow Summary of Conceptual Design Conceptual design follows requirements analysis, Yields a high-level description of data to be stored ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. Basic constructs: entities, relationships, and attributes (of entities and relationships). Some additional constructs: weak entities, ISA hierarchies, and aggregation. Note: There are many variations on ER model.

25 Engineered for Tomorrow
Summary of ER (Contd.) Several kinds of integrity constraints can be expressed in the ER model: key constraints, participation constraints, and overlap/covering constraints for ISA hierarchies. Some foreign key constraints are also implicit in the definition of a relationship set. Some constraints (notably, functional dependencies) cannot be expressed in the ER model. Constraints play an important role in determining the best database design for an enterprise.

26 Engineered for Tomorrow
Summary of ER (Contd.) ER design is subjective. There are often many ways to model a given scenario. Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include: Entity vs. attribute, entity vs. relationship, binary or n-ary relationship, whether or not to use ISA hierarchies, and whether or not to use aggregation. Ensuring good database design: resulting relational schema should be analyzed and refined further. FD information and normalization techniques are especially useful.

27 Engineered for Tomorrow
Example Assume we have the following application that models cricket teams, capture the following information in the ER- Diagram We have a set of teams, each team has an ID, name, stadium, and to which country this team belongs. Each team has many players, and each player belongs to one team. Each player has a number, name, DoB, start year, and jersey number that he uses. Teams play matches, in each match there is a host team and a guest team. The match takes place in the stadium of the host team. For each match we need to keep track of the following: The date on which the match is played The final result of the match The players participated in the match. For each player, how many runs he scored, whether or not he took wickets, and whether or not he scored 100’s. Each match has exactly three umpires. For each umpire we have an ID, name, DoB, years of experience. Two umpires are main and the other one is the third umpire.

28 PLAYER TEAM MATCH- PLAYER MATCHES UMPIRE P_Num P_Name Dob Jersey_No Start_Year Stadium Country Name ID Is Main DOB ExpYears Date Score Host Score Runs Wickets 100’s Plays Belongs_to Host Guest In_match role Guest Score

29 Example Company stores information on its shipped item. The requirements are as follows Shipped items can be characterized by item number (unique), weight, insurance amount, destination and delivery date. Shipped items are received at a single trade center. Trade centers are characterized by their type, ID, and address. Shipped items are dispatched via one or more standard transportation. These transportation are characterized by a unique schedule Number, mode (e.g, airways, waterways, roadways), and a delivery Route. Create an E-R diagram that captures this information.

30 Item_No Shipped Items Weight InsurancAmt Destination DeliverDate Trade Center Transportation ScheduleNo Route Mode Address Type ID Received From Via Airways Waterways Roadways ZIP City Country Street N 1


Download ppt "DATABASE MANAGEMENT SYSTEMS"

Similar presentations


Ads by Google