Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Data Models
Data abstraction
- one fundamental characteristic of the database approach
- hides details of data storage that are not needed by most database users and
applications
Data model
- a set of data structures and conceptual tools used to describe the structure of
a database (data types, relationships, and constraints)
- used in the definition of the conceptual, external, and internal schema
- must provide means for DB designers to represent the real-world
information completely and naturally.
Data Models
High-level (conceptual) data models
- use concepts such as entities, attributes, relationships
- object-based models: ER model, OO model
Representational (implementation) data models
- most frequently used in commercial DBMSs
- record-based models: relational, hierarchical, network
Low-level (physical) data models
- to describe the details of how data is stored
- captures aspects of database system implementation: record structures
(fixed/variable length) and ordering, access paths (key indexing), etc.
Schemas and Instances
In any data model, it is important to distinguish between the description of
the database and the database itself. Database schema (meta-data)
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
several types.
Each record type defines a fixed number of fields, or attributes.
Each field is usually of a fixed length (this simplifies the implementation).
The three most widely accepted models are the
Relational, network, and hierarchical data model.
Physical Data Models
1. Are used to describe data at the lowest level.
2. Very few models, e.g.
Unifying model.
Frame memory.
Entity-relationship model
- popular high-level conceptual model used in DB design
- proposed by P. Chen in 1976 (ACM TODS)
- Perception of real-world consisting of a collection of entities and
relationships among them OO model.
- DB is defined in terms of objects, their properties, and their operations
(methods) Relational model
- represents a DB as a collection of tables Network model
- represents DB as record types and 1:N relationships Hierarchical model
- represents data as hierarchical tree structures
An entity may be defined as a thing which is recognized as being capable of
an independent existence and which can be uniquely identified. An entity is
an abstraction from the complexities of some domain.
E-R Diagram Notation:
Entity Key attributes
Weak Entity Multivalue
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
attribute
Relationship
Attributes Composite
Attributes
Relationship between two entities
ER Diagrams
Rectangles represent entity sets.
-Diamonds represent relationship sets.
-Lines link attributes to entity sets and entity sets to relationship sets.
-Ellipses represent attributes
-Double ellipses represent multivalve attributes.
-Dashed ellipses denote derived attributes.
-Underline indicates primary key attributes (will study later)
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
ManyToOneRelationships:
In a many to one relationship a loan is associated with several (including
0) customers via borrower, a customer is associated with at most one
Loan via borrower.
ManyToMany Relationship:
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Specialization Example:
Entities: Entity-a thing (animate or inanimate) of independent physical or
conceptual existence and distinguishable. In the University database context,
an individual student, faculty member, a class room, courses are entities.
Entity Set or Entity Type-Collection of entities all having the same
properties. Student entity set collection of all student entities. Course entity
set collection of all course entities
Attributes - Each entity is described by a set of attributes/properties.
Student entity Stud Namename of the student.
Roll Numberthe roll number of the student.
Sexthe gender of the student etc. All entities in an Entity set/type have the
same set of attributes
Types of Attributes
Simple Attributes-having atomic or indivisible values.
example: Depta string Phone Numberan eight digit number
Composite Attributes-having several components in the value.
example: Qualification with components (Degree Name, Year, University
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Name)
Derived Attributes-Attribute value is dependent on some other attribute.
Example: Age depends on Date Of Birth. So age is a derived attribute.
Single-valued-having only one value rather than a set of values.
-for instance, Place Of Birthsingle string value.
Multi-valued -having a set of values rather than a single value.
-for instance, Courses Enrolled attribute for student Email Address attribute
for student Previous Degree attribute for student.
Attributes can be:-simple single-valued, simple multi-valued,composite
single-valued or composite multi-valued
Diagrammatic Notation for Entities entity -rectangle attribute -ellipse
connected to rectangle multi-valued attribute -double ellipse composite
attribute -ellipse connected to ellipse derived attribute-dashed ellipse
Relationships
When two or more entities are associated with each other, we have an
instance of a Relationship.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Cardinality Ratios/Mappings
One-to-one: An E1entity may be associated with at most one E2 entity and
similarly an E2entity may be associated with at most one E1 entity.
One-to-many: An E1entity may be associated with many E2entities whereas
an E2entity may be associated with at most one E1entity
.Many-to-one: ( similar to above)
Many-to-many: Many E1entities may be associated with a single E2 entity
and a single E1entity may be associated with many E2entities
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Key Attributes:
Primary Key: The primary key of a relational table uniquely identifies each
record in the table. It can either be a normal attribute that is guaranteed to be
unique (such as Social Security Number in a table with no more than one
record per person) or it can be generated by the DBMS.
Examples: Imagine we have a STUDENTS table that contains a record for
each student at a university. The student's unique student ID number would
be a good choice for a primary key in the STUDENTS table. The student's
first and last name would not be a good choice, as there is always the chance
that more than one student might have the same name.
Foreign Key:A foreign key is a field in a relational table that matches the
primary key column of another table. The foreign key can be used to cross-
reference tables
Referential Integrity
Referential integrity is a database concept that ensures that relationships
between tables remain consistent. When one table has a foreign key to
another table, the concept of referential integrity states that you may not add a
record to the table that contains the foreign key unless there is a
corresponding record in the linked table. It also includes the techniques
known as cascading update and cascading delete, which ensure that changes
made to the linked table are reflected in the primary table.
Referential integrity enforces the following three rules:
1. We may not add a record to the Employees table unless the Managed By
attributes points to a valid record in the Managers table.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
2. If the primary key for a record in the Managers table changes, all
corresponding records in the Employees table must be modified using a
cascading update.
3. If a record in the Managers table is deleted, all corresponding records in
the Employees table must be deleted using a cascading delete.
Importance of Referential Integrity
By providing specification of columns within a referencing table that are
foreign keys for columns in some other referenced table, referential integrity
is a reliable mechanism which prevents accidental database corruptions when
doing inserts, updates, and deletes. It states that a row cannot exist in a table
with a non-null value for a referencing column if an equal value does not
exist in a referenced column.
Once we define the employee_number as a foreign key in employee_phone
relation, if we try to insert a row with a primary key value that does not exist
in employee table, the system will not allow this insertion.
The following summarize the benefits of referential integrity:
a) Ensure data integrity and consistency base on primary key and foreign key
b) Increases development productivity, because it is not necessary to code
SQL statements to enforce referential constraints, the Teradata RDBMS
automatically enforces referential integrity.
Candidate Key:
A candidate key is a combination of attributes that can be uniquely used to
identify a database record without any extraneous data. Each table may have
one or more candidate keys. One of these candidate keys is selected as the
table primary key.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Check Constraint:
A check constraint (also known as table check constraint) is a condition that
defines valid data when adding or updating an entry in a table of a relational
database. A check constraint is applied to each row in the table. The
constraint must be a predicate. It can refer to a single or multiple columns of
the table. The result of the predicate can be TRUE, FALSE, or UNKNOWN,
depending on the presence of NULLs. If the predicate evaluates to
UNKNOWN, then the constraint is not violated and the row can be inserted
or updated in the table.
Each check constraint has to be defined in the CREATE TABLE or ALTER
TABLE statement using the syntax:
1. CREATE TABLE table_name (...,CONSTRAINT constraint_name CHECK (
predicate ), ... )
2. ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (
predicate )
NOT NULL Constraint:
A NOT NULL constraint is functionally equivalent to the following check constraint
with an IS NOT NULL predicate:CHECK (column IS NOT NULL)
Domain Constraints:
A domain is defined as the set of all unique values permitted for an attribute.
For example, a domain of date is the set of all possible valid dates, a domain
of integer is all possible whole numbers, a domain of day-of-week is
Monday, Tuesday ... Sunday.
This in effect is defining rules for a particular attribute. If it is determined that
an attribute is a date then it should be implemented in the database to prevent
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
Database Administrator
n Coordinates all the activities of the database system; the
database administrator has a good understanding of the Enterprises
information resources and needs.
Database administrator's duties include:
-Schema definition
-Storage structure and access method definition
-Schema and physical organization modification
-Granting user authority to access the database
-Specifying integrity constraints
-Acting as liaison with users
-Monitoring performance and responding to changes in
requirements
Keys:
-A super key of an entity set is a set of one or more attributes
whose values uniquely determine each entity.
-A candidate key of an entity set is a minimal super key
l Customer_id is candidate key of customer
l account_number is candidate key of account
-Although several candidate keys may exist, one of the candidate
keys is selected to be the primary key.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1
kLAkLD 8 Asst.rof.SAN1CSn