Professional Documents
Culture Documents
Spatial Data Base Chapter Two - Data Modellig 4th Year
Spatial Data Base Chapter Two - Data Modellig 4th Year
Spatial Data Base Chapter Two - Data Modellig 4th Year
Data Modeling
1
Outline
1.Overview
2. Data Modeling Using The Entity-Relationship Model
– Conceptual Data Models For Database Design
– An Example Database Application
– Entity Types, Entity Sets, Attributes, and Keys
– Relationship Types
– Design Choices For ER Conceptual Design
3
1.2 Why Data Models?
Data models facilitate
Early analysis of properties, e.g. storage cost, querying ability, ...
Reuse of shared data among multiple applications
Exchange of data across organization
Conversion of data to new software / environment
Example- Y2K crisis for year 2000
Many computer software systems were developed without well-
defined data models in 1960s and 1970s. These systems used a variety
of data models for representing time and date. Some of the
representations used two digits to represent years. In late 1990s, people
worried that the 2 digit representation of year may lead to erroneous
behavior.
4
For example age of a person born in 1960 (represented as 60) in year
2000 (represented as 00) may appear negative and may be flagged as
illegal data item. A large amount of effort and resources (hundreds of
Billions of dollars) was spent in revising the software.
Proper use of data model may have significantly reduced the costs. If
time and date were modeled as abstract data types in a software, only a
small portion of the software implementing the date ADT had to be
reviewed and revised.
5
2. Data Modeling Using The Entity-Relationship Model
6
• Phase Two:The Conceptual schema
– is a concise description of the data requirements of the users and
includes detailed descriptions of the entity types, relationships,
and constraints; these are expressed using the concepts provided
by the high-level data model.
– The high-level conceptual schema can also be used as a reference
to ensure that all users' data requirements are met and that the
requirements do not conflict
• Pahse Three: The Logical Design
– It is the actual implementation of the database, using a
commercial DBMS.
– conceptual schema is transformed from the high-level data model
into the implementation data model.
• Phase Four: physical design
– during which the internal storage structures, indexes( access
paths) and file organizations for the database files are specified
7
2.2 AN EXAMPLE DATABASE Application
Assume that we want to Create a database application called Company
The COMPANY database keeps track of a company's employees,
departments, and projects. Suppose that after the requirements
collection and analysis phase, the database designers provided the
following description of the "miniworld
i. The company is organized into departments. Each department has a
unique name, a unique number, and a particular employee who
manages the department. We keep track of the start date when that
employee began managing the department.
ii. A department controls a number of projects, each of which has a
unique name, a unique number, and a single location.
iii. We store each employee's name, social security number,address,
salary, sex, and birth date. An employee is assigned to one
department but may work on several projects, which are not
necessarily controlled by the same department. We keep track of the
number of hours per week that an employee works on each project.
We also keep track of the direct supervisor of each employee. 8
FIGURE 2.2 : An ER schema diagram for the COMPANY
database.
9
2.3 ENTITY TYPES, ENTITY SETS,ATTRIBUTES, AND KEYS
• Entities and 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 (for
example, a particular person, car, house, or employee) or it may be an
object with a conceptual existence (for example, 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. 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.
• WEAK ENTITY TYPES-Entity types that do not have key attributes of their
10
own are called weak entity types.
FIGURE 2.3 : Preliminary design of entity types for the COMPANY
database.
11
2.4 RELATIONSHIP
There are several implicit relationships among the various entity types.
For example, the attribute Manager of DEPARTMENT refers to an
employee who manages the department;
The attribute Controlling Department of PROJECT refers to the
department that controls the project;
The attribute Department of EMPLOYEE refers to the department
for which the employees works; and so on.
In the ER model, these references should not be represented as
attributes but as relationships, which are discussed later on.
• In ER diagrams, relationship types are displayed as diamond-shaped
boxes, which are connected by straight lines to the rectangular boxes
representing the participating entity types.
12
FIGURE 2.5
Summary of the notation for ER
diagrams.
13
FIGURE 2 . 6 Part of an ER diagram for a COMPANY database.
Slide 2-14
FIGURE 2.7 Part of an ER diagram for a COURSES database.
15
2.5 CONCEPTUAL DESIGN FOR LARGE ENTERPRISES
Key of a Relation: Each row has a value of a data item (or set of items) that
uniquely identifies that row in the table Called the key . Here SSN is the key
Remark: we display the relation as a table, where each tuple is shown as a row and each attribute
corresponds to a column header indicating a role or interpretation of the values in that column. Null values
represent attributes whose values are unknown or do not exist for some individual STUDENT tuple.
22
The degree of a relation is the number of attributes n of its
relation schema.
A relation schema R of degree n is denoted by
R(A1 , A2 , …, An )
The domain of Ai is denoted by dom(Ai).
DEFINITION SUMMARY
27
One possible database state for the COMPANY relational database schema
28
ii. Entity Integrity
The primary key attributes PK of each relation schema R in S
cannot have null values in any tuple of r(R).
This is because primary key values are used to identify
the individual tuples.
t[PK] null for any tuple t in r(R)
If PK has several attributes, null is not allowed in any of
these attributes
Note: Other attributes of R may be constrained to disallow null values, even
though they are not members of the primary key.
iii. Referential Integrity
A constraint involving two relations.
Used to specify a relationship among tuples in two relations:
the referencing relation and the referenced relation.
Tuples in the referencing relation R1 have attributes FK (called
foreign key attributes) that reference the primary key
attributes PK of the referenced relation R2. A tuple t1 in R1 is
29
said to reference a tuple t2 in R2 if t1[FK] = t2[PK].
Displaying a relational database schema and its constraints
30
31
3. 3 Populated database state
Each relation will have many tuples in its current relation state
The relational database state is a union of all the individual
relation states
Whenever the database is changed, a new state arises
Basic operations for changing the database:
INSERT a new tuple in a relation
DELETE an existing tuple from a relation
MODIFY an attribute of an existing tuple
Next slide shows an example state for the COMPANY database
32
Populated database state for COMPANY
33
Possible violations for each operation
INSERT may violate any of the constraints:
– Domain constraint:
• if one of the attribute values provided for the new tuple is not
of the specified attribute domain
– Key constraint:
• if the value of a key attribute in the new tuple already exists
in another tuple in the relation
– Entity integrity:
• if the primary key value is null in the new tuple
– Referential integrity:
• if a foreign key value in the new tuple references a primary
key value that does not exist in the referenced relation
34
• DELETE- may violate only referential integrity:
– If the primary key value of the tuple being deleted is
referenced from other tuples in the database
• UPDATE- may violate domain constraint and NOT NULL
constraint on an attribute being modified
– Any of the other constraints may also be violated,
depending on the attribute being updated:
• Updating the primary key (PK):
• Updating a foreign key (FK):
– May violate referential integrity
• Updating an ordinary attribute (neither PK nor FK):
– Can only violate domain constraints
35
Exercise
Consider the following relations for a database that keeps track of student
enrollment in courses and the books adopted for each course:
STUDENT(SSN, Name, Major, Bdate)
COURSE(Course#, Cname, Dept)
ENROLL(SSN, Course#, Quarter, Grade)
BOOK_ADOPTION(Course#, Quarter, Book_ISBN)
TEXT(Book_ISBN, Book_Title, Publisher, Author)
Draw a relational schema diagram specifying the foreign keys for this
schema.
36