The Relational Data Model: Structure



Similar documents
Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

Relational Database Concepts

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Data Modeling. Database Systems: The Complete Book Ch ,

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Relational Databases

Once the schema has been designed, it can be implemented in the RDBMS.

EECS 647: Introduction to Database Systems

Databases What the Specification Says

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

The Relational Model. Why Study the Relational Model?

Data Modeling Basics

The Relational Data Model and Relational Database Constraints

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

Lecture 6. SQL, Logical DB Design

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

Lesson 8: Introduction to Databases E-R Data Modeling

How To Manage Data In A Database System

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Database Design Methodology

Logical Schema Design: The Relational Data Model

Chapter 2: Entity-Relationship Model. E-R R Diagrams

Doing database design with MySQL

3. Relational Model and Relational Algebra

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Relational Database Basics Review

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Oracle Database 10g Express

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

ER modelling, Weak Entities, Class Hierarchies, Aggregation

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

The Entity-Relationship Model

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

Databases and BigData

Ken Goldberg Database Lab Notes. There are three types of relationships: One-to-One (1:1) One-to-Many (1:N) Many-to-Many (M:N).

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

Database Design Process. Databases - Entity-Relationship Modelling. Requirements Analysis. Database Design

12 File and Database Concepts 13 File and Database Concepts A many-to-many relationship means that one record in a particular record type can be relat

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

Fundamentals of Database Design

Conceptual Design Using the Entity-Relationship (ER) Model

The core theory of relational databases. Bibliography

Relational Databases and SQLite

Introduction This document s purpose is to define Microsoft SQL server database design standards.

Announcements. SQL is hot! Facebook. Goal. Database Design Process. IT420: Database Management and Organization. Normalization (Chapter 3)

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

1. INTRODUCTION TO RDBMS


Below is a table called raw_search_log containing details of search queries. user_id INTEGER ID of the user that made the search.

Relational Databases. Christopher Simpkins

Entity/Relationship Modelling. Database Systems Lecture 4 Natasha Alechina

There are five fields or columns, with names and types as shown above.

How To Handle Missing Information Without Using NULL

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

2. Basic Relational Data Model

Why & How: Business Data Modelling. It should be a requirement of the job that business analysts document process AND data requirements

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

Entity-Relationship Model

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Excel 2003, MS Access 2003, FileMaker Pro 8. Which One Should I Use?

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

7. Databases and Database Management Systems

DbSchema Tutorial with Introduction in SQL Databases

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

2. Conceptual Modeling using the Entity-Relationship Model

Database Systems. Lecture 1: Introduction

Database Design and the E-R Model

Topic: Relationships in ER Diagram and Relationships in MS Access

CDC UNIFIED PROCESS PRACTICES GUIDE

What Is Singapore Math?

CSCE 156H/RAIK 184H Assignment 4 - Project Phase III Database Design

Chapter 2. Data Model. Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel

XV. The Entity-Relationship Model

CS411 Database Systems

The process of database development. Logical model: relational DBMS. Relation

Database Fundamentals

BİL 354 Veritabanı Sistemleri. Entity-Relationship Model

CHAPTER 6 DATABASE MANAGEMENT SYSTEMS. Learning Objectives

Reading 13 : Finite State Automata and Regular Expressions

Review: Participation Constraints

Chapter 3. Data Modeling Using the Entity-Relationship (ER) Model

Database Constraints and Design

SQL Server. 1. What is RDBMS?

Database Design. Adrienne Watt. Port Moody

Fundamentals of Database System

Limitations of E-R Designs. Relational Normalization Theory. Redundancy and Other Problems. Redundancy. Anomalies. Example

Transcription:

The Relational Data Model: Structure 1 Overview By far the most likely data model in which you ll implement a database application today. Of historical interest: the relational model is not the first implementation data model. Prior to that were the network data model, exemplified by CODASYL, and the hierarchical model, implemented by IBM s IMS. Also of historical interest: when object-oriented programming gained prominence, there were many attempts to replace a relational database with an object database, but generally they did not fare well. Today, object-oriented concepts co-exist with underlying relational databases through object-relational mapping algorithms. Salient features of the relational model: Conceptually simple; the fundamentals are intuitive and easy to pick up. Powerful underlying theory: the relational model is the only database model that is powered by formal mathematics, which results in excellent dividends when developing database algorithms and techniques. Easy-to-use database language: though not formally part of the relational model, part of its success is due to SQL, the de facto language for working with relational databases. 2 Structure A relational database is a collection of tables. Each table has a unique name. Each table consists of multiple rows. Each row is a set of values that by definition are related to each other in some way; these values conform to the attributes or columns of the table. 1

Each attribute of a table defines a set of permitted values for that attribute; this set of permitted set is the domain of that attribute. This definition of a database table originates from the pure mathematical concept of a relation, from which the term relational data model originates. Formally, for a table r with n attributes a 1... a n, each attribute a k has a domain D k, and any given row of r is an n-tuple (v 1,..., v n ) such that v k D k. Thus, any instance of table r is a subset of the Cartesian product D 1 D n. We require that a domain D k be atomic that is, we do not consider the elements of D k to be breakable into subcomponents. A possible member of any domain is null that is, an unknown or non-existent value; in practice, we try to avoid the inclusion of null in our databases because they can cause a number of practical issues. This definition is virtually identical to the pure mathematical definition of a relation the main difference is that, for a database, we assign names to the table s attributes, where mathematical relations only label their attributes by their integer indices 1... n. To avoid jargon proliferation, we will stick with the more formal terms relation for table and tuple for row which is why we used r to represent a table above instead of t. More notation: Given a tuple t that belongs to a relation r, we can say that t R since after all r is a set of tuples. By set of tuples we do mean the mathematical concept of a set; thus order doesn t matter. Two relations r and s are the same as long as they have the same attributes a 1... a n with domains D 1... D n and contain as elements the same tuples with the same values, regardless of the order in which these tuples appear. To talk about a specific attribute a k of t, we write t[a k ]. This notation also applies to a set of attributes A the notation t[a] refers to the sub-tuple of t consisting only of the attributes in A. Alternatively, t[k] can refer to that same attribute of t, as long as we are consistent about how attributes are ordered in the relation. 2.1 Schemas and Instances Just as with classes and instances in the object-oriented world, a similar dichotomy exists between a database schema and a database instance. 2

The schema refers to the database s design or definition what relations it contains, what attributes these relations have, and to what domains these attributes belong. An instance of the database is a specific snapshot of the data in that database at a given point in time. Ditto with relation schemas lists of attributes and their corresponding domains and relation instances. The SKS convention is to use names with an initial uppercase letter to represent a relation schema, and all-lowercase for a relation instance (or, simply, a relation). The notation r(r schema) indicates that the relation r conforms to a schema R schema. 2.2 Keys: Super, Candidate, Primary, Foreign Since a tuple t is completely defined by its values (v 1... v n ), there is no way to differentiate between t = (v 1... v n ) and t = (v 1... v n) if v k = v k 1 k n. In the relational model, two such tuples are one and the same. Thus, we need a value-based way for differentiating tuples in a relation. Values or sets of values that distinguish one tuple from another are called keys. A superkey is a set of one or more attributes that uniquely identify a tuple in a relation. The superkey can range from a single attribute, if no two tuples will ever have the same value for that attribute, to the entire tuple. As long as the set of attributes will distinguish tuples from each other, then it is a superkey. Thus, if K is a superkey, then any superset of K up to the entire attribute set is also a superkey. More formally, if R is a relation schema, then a subset K of R is a superkey for R if, for a relation r(r) and tuples t 1 and t 2 in r, t 1 t 2 t 1 [K] t 2 [K]. In practice, a superkey is not very useful; we need a stricter definition for a key, which is... A candidate key is a minimal superkey it is a superkey for which no proper subset is also a superkey. Note that there can still be more than one candidate key for a relation, consisting of different subsets of attributes whose combined values will be unique for all tuples. So we finally narrow things down to the primary key: the primary key is a candidate key that has been chosen by the database designer as the principal means for identifying tuples in a relation. 3

One of the key guidelines (ha! no pun intended, I think... ) that makes a candidate key particularly suited for elevation to the status of the one primary key is that the value of the candidate key should never, or very rarely, change. Say you have two relation schemas R 1 and R 2 and these schemas share some subset of attributes. If K p is the primary key of R 2 and K p R 1 as well in other words, R 1 s attributes include the primary key of R 2 then K p is a foreign key from R 1 referencing R 2. R 1, the relation that contains the foreign key, is the referencing relation. R 2, the relation for which K p is a primary key, is the referenced relation. In practice, specifying a foreign key places a constraint on the data that any r 1 (R 1 ) and r 2 (R 2 ) may contain: that is, tuples t 1 r 1, there must be a tuple t 2 r 2 such that t 1 [P k ] = t 2 [P k ]. Quick clearly there is only one such tuple t 2. Why? 3 Relational Schema Diagram Notation student student_id lastname firstname advisor document document_id timestamp title description locator student_id user_id doc_keyword document_id keyword_id user user_id login password isadmin keyword keyword_id term description Figure 1: Sample relational schema diagram for our sample document management database application. A relational database schema can be depicted pictorially through a relational schema diagram. Yes, it s yet another notation like E-R and UML, but this notation is very focused and specific to the relational data model: Relations are drawn as boxes with the relation name above the box. A relation s attributes are listed within its box. The attributes that belong to the relation s primary key (if it has one) are listed first, with a line separating this primary key from the other attributes and their background shaded in gray. Foreign key dependencies are illustrated as arrows from the foreign key attributes of the referencing relation to the primary key attributes of the referenced relation. 4

Figure 1 illustrates a possible relational schema diagram for our sample document management database application, with the id attribute for each class serving as the primary key for the corresponding table and foreign key attributes added to represent the associations between classes. Note how we have added another relation to represent the association between documents and keywords this is a standard technique for expressing a many-to-many relationship in terms of the relational data model. How about a 1-to-many relationship can you see from the diagram how that kind of relationship gets mapped to the relational model? 5