4)A Logical View of Data
• Relational model
– Enables programmer to view data logically rather than physically
• Table
– Has advantages of structural and data independence
– Resembles a file from conceptual point of view
– Easier to understand than its hierarchical and network database predecessors
Tables and Their Characteristics
• Table: two-dimensional structure composed of rows and columns
• Contains group of related entities = an entity set
– Terms entity set and table are often used interchangeably
– Table also called a relation because the relational model’s creator, Codd, used the term
relation as a synonym for table
– Think of a table as a persistent relation:
– A relation whose contents can be permanently saved for future use
–
Keys
• Consists of one or more attributes that determine other attributes
• Primary key (PK) is an attribute (or a combination of attributes) that uniquely identifies any given
entity (row)
• Key’s role is based on determination
– If you know the value of attribute A, you can look up (determine) the value of attribute B
• Foreign key (FK)
– An attribute whose values match primary key values in the related table
• Referential integrity
– FK contains a value that refers to an existing valid tuple (row) in another relation
• Secondary key
– Key used strictly for data retrieval purposes
Candidate Key
• A Candidate Key can be any column or a combination of columns that can qualify as unique key
in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify
as Primary Key.
How to select Primary Key
• select a key that does not contain NULL
• Select a key that is unique and does not repeat
• Make sure that Primary Key does not keep changing
Keys (continued)
• Nulls:
– No data entry
– Not permitted in primary key
– Should be avoided in other attributes
– Can represent
• An unknown attribute value
• A known, but missing, attribute value
• A “not applicable” condition
– Can create problems when functions such as COUNT, AVERAGE, and SUM are used
– Can create logical problems when relational tables are linked
• Controlled redundancy:
– Makes the relational database work
– Tables within the database share common attributes that enable the tables to be linked
together
– Multiple occurrences of values in a table are not redundant when they are required to
make the relationship work
– Redundancy exists only when there is unnecessary duplication of attribute values
Integrity Rules
The Data Dictionary and System Catalog
• Data dictionary
– Provides detailed accounting of all tables found within the user/designer-created
database
– Contains (at least) all the attribute names and characteristics for each table in the
system
– Contains metadata—data about data
– Sometimes described as “the database designer’s database” because it records the
design decisions about tables and their structures