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



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

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

Lecture 6. SQL, Logical DB Design

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

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

Data Modeling. Database Systems: The Complete Book Ch ,

Review: Participation Constraints

The Relational Model. Why Study the Relational Model?

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

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

The Relational Data Model: Structure

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

Conceptual Design Using the Entity-Relationship (ER) Model

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

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

Chapter 6: Integrity Constraints

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

The Relational Data Model and Relational Database Constraints

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

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

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

EECS 647: Introduction to Database Systems

Section of DBMS Selection & Evaluation Questionnaire

The Entity-Relationship Model

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

Relational Database Basics Review

SQL NULL s, Constraints, Triggers

How To Create A Table In Sql (Ahem)

The SQL Query Language. Creating Relations in SQL. Referential Integrity in SQL. Basic SQL Query. Primary and Candidate Keys in SQL

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

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

Chapter 23. Database Security. Security Issues. Database Security

Answers included WORKSHEET: INTEGRITY CONTROL IN RELATIONAL DATABASES

Chapter 9: Object-Based Databases

3. Relational Model and Relational Algebra

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

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

Using SQL Server Management Studio

Exercise 1: Relational Model

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

CPS352 Database Systems: Design Project

2. Basic Relational Data Model

IT2304: Database Systems 1 (DBS 1)

Logical Schema Design: The Relational Data Model

Instant SQL Programming

Database Design and Normalization

Databases and BigData

Quiz! Database Indexes. Index. Quiz! Disc and main memory. Quiz! How costly is this operation (naive solution)?

Advance DBMS. Structured Query Language (SQL)

Relational Databases

A basic create statement for a simple student table would look like the following.

Lesson 8: Introduction to Databases E-R Data Modeling

Introduction to Databases

Normal Form vs. Non-First Normal Form

Normalization in Database Design

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

Introduction to tuple calculus Tore Risch

Schema Evolution in SQL-99 and Commercial (Object-)Relational DBMS

New York University Computer Science Department Courant Institute of Mathematical Sciences

Tutorial on Relational Database Design

How To Manage Data In A Database System

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

IT2305 Database Systems I (Compulsory)

Databases What the Specification Says

SQL: Queries, Programming, Triggers

SQL Server An Overview

Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables

Fundamentals of Database Design

Functional Dependency and Normalization for Relational Databases

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

Information Systems SQL. Nikolaj Popov

SQL: Queries, Programming, Triggers


Oracle Database 10g Express

Chapter 5: FUNCTIONAL DEPENDENCIES AND NORMALIZATION FOR RELATIONAL DATABASES

Database Design Patterns. Winter Lecture 24

DISCRETIONARY ACCESS CONTROL. Tran Thi Que Nguyet Faculty of Computer Science & Engineering HCMC University of Technology ttqnguyet@cse.hcmut.edu.

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

Introduction to Microsoft Jet SQL

Foreign and Primary Keys in RDM Embedded SQL: Efficiently Implemented Using the Network Model

CSC 443 Data Base Management Systems. Basic SQL

The core theory of relational databases. Bibliography

Basic Concepts of Database Systems

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access


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

COSC344 Database Theory and Applications. Lecture 9 Normalisation. COSC344 Lecture 9 1

Maintaining Stored Procedures in Database Application

Oracle Database 12c: Introduction to SQL Ed 1.1

2. Conceptual Modeling using the Entity-Relationship Model

SQL Server. 1. What is RDBMS?

Performance Evaluation of Natural and Surrogate Key Database Architectures

BCA. Database Management System

Enforcing Data Quality Rules for a Synchronized VM Log Audit Environment Using Transformation Mapping Techniques

SQL Tables, Keys, Views, Indexes

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

Normalization in OODB Design

5.1 Database Schema Schema Generation in SQL

Transcription:

COS 597A: Principles of Database and Information Systems elational model elational model A formal (mathematical) model to represent objects (data/information), relationships between objects Constraints on objects and relationships Queries about information Well-founded on mathematical principles : Precise semantics of constraints and queries Can prove equivalence of different ways to express queries elational model - practice Foundation of most Database Management Systems SQL language is a programming language to express constructs of formal model elational Database Definitions 1. A relation is a set of tuples over specified domains subset of D 1 X D 2 X D 3 X D k (k-ary) Each D i is a declared domain Domains atomic types of programming languages 2. A relational database is a set of relations and possibly constraints among the relations elational Database: Terminology Schema for a relation: 1. elation name 2. Domain (type) of each component i.e. declare D i s Equivalent: Instance of a scheme Table Term relation is used to refer to a schema and a particular instance disambiguate by context elational Database: More Terminology Each D i of a schema is referred to as a component or attribute or field or column of the schema Each d i of a tuple = (d 1, d 2, d 3, d k ) is referred to as component or attribute or field of the tuple Each tuple of a relation is also referred to as an element or row of the relation attributes elements 1

Translating E model to relational Domains domains Entity relation elationship one* or more relations * come back to Constraints constraints BUT Not all E constraints expressible in basic relational model elational model is FLAT no hierarchy! For entities, get relations: books: (title, ISBN#, edition, date) authors: (name, gender, birth date, place of birth, date of death) publishers: (name, country, address) Need declare domains: e.g. title: string Same defs candidate keys, primary key, superkeys For relationships: E published by: (books, publishers, in print) becomes published by: (isbn#, publisher_name, in print) key constraint on entity books in relationship published by A book has at most one publisher E written by: (books, authors) becomes written by: (isbn#, author_name, birth date, place of birth) Because E key constraint on entity books in relationship published by Can fold relation published by into relation books: books: (title, ISBN#, edition, date, pub_name, in print) What if some books not published? i.e. entity books not totally participate in relationship published by books: (title, ISBN#, edition, date, pub_name, in print) What if some books not published? i.e. entity books not totally participate in relationship published by Translating E model to relational General conclusion: elationship one zero or more relations Must allow values of attributes pub_name and in print to be null 2

Translating E model to relational Get flat set of relations But relations are interrelated Bring together primary keys of different relations to build new relation Captures E relationship How capture this in relational model? Foreign key constraints Foreign key constraint Specify that a set of attributes in schema for one relation form a primary key for a specific other relation other relation is referred to or referenced by first relation 1: (attrib1, attrib2, attrib3, attrib4, attrib5) 1 refers to/references 2 2: (attrib1, attrib2, attrib3, attrib4) Foreign Keys for Our Example published by: (isbn#, publisher_name, in print) isbn# is a foreign key referencing books Primary key of books understood Publisher_name is a foreign key referencing publishers written by: (isbn#, author_name, birth date, place of birth ) isbn# is a foreign key referencing books; (author_name, birth date, place of birth) is a foreign key referencing authors Summary of board example: with Copies as weak entity Books book Copies holding Because E key constraints book folded into Copies holding folded into Copies elational model: branches: (br_name, librarian, hours) Copies: (ISBN#, copy#, condition, br_name) branches Summary of board example: with Copies as strong entity Summary of board example: Alternative with Copies as strong entity Books book holding branches Books book holding branches call # copy # Copies condition elational model: branches: (br_name, librarian, hours) Copies: (ISBN#, call #, copy #, condition, br_name) Because E key constraints book folded into Copies holding folded into Copies ISBN# not null NEW Copies Because E key constraints elational model: book folded into Copies branches: (br_name, librarian, hours) Copies: (ISBN#, call #, copy #, condition) ISBN# not null holding: (call #, copy #, br_name) (call #, copy #) is a foreign key referencing Copies 3

Board example: Total participation of Copies? Copies: (ISBN#, call #, copy #, condition, br_name) ISBN# not null capture total participation in book and holding because book, holding represented within Copies versus holding: (call #, copy #, br_name) (call #, copy #) is a foreign key referencing Copies Board example: Total participation of branches? Can t get constraint applied to all branch tuples without being part of branch relation Total participation of branches in holding not representable in pure relational definition br_name not null would not capture that every (call #, copy #) value is in a holding pair Attribute _A 1 Entity 1 Basic Paradigm Attribute _A m Entity k Entity 2 Entity k-1 Each entity becomes a relation elationship becomes : { (list of attributes forming key of Entity 1 (denote L 1 ), list of attributes forming key of Entity 2 (denote L 2 ), list of attributes forming key of Entity k (denote L k ), Attribute _A 1,, Attribute _A m ) L 1 is a foreign key referencing Entity 1, L k is a foreign key referencing Entity k } Note primary key What about constraints on relationships? Key constraint: Simplifies key of corresponding relation Allows folding of relation into key entity Total participation constraint: In general, cannot represent in purely relational definition: Domain specification Keys of relations Foreign keys not null s } Constraints have in relational definition For Basic Paradigm (binary relationship) r 1 r m Clarifying null values and foreign keys Entity A Entity B a 1 a p x 1 xu b 1 yv Each entity becomes a relation with same attributes elationship becomes : { (a 1,, a p, b 1,, b q, r 1,, r m ) (a 1,, a p) is a foreign key referencing A, (b 1,, b q ) is a foreign key referencing B } b q y 1 can be no null values among a i and b j in tuple of make up s primary key 4

When one entity (e.g. Entity A) has key constraint and fold into it r 1 r m When have key constraint and total participation and fold in r 1 r m Entity A Entity B Entity A Entity B a 1 a p x 1 xu b 1 yv Entity B becomes a relation with same attributes elationship becomes part of relation for Entity A: A: { (a 1,, a p, x 1,, x u, b 1,, b q, r 1,, r m ) (b 1,, b q ) is a foreign key referencing B } now need to allow null values for b 1 b q in A not every entity in A is related to an entity in B b q y 1 a 1 a p x 1 xu b 1 yv Entity B becomes a relation with same attributes elationship becomes part of relation for Entity A: A: { (a 1,, a p, x 1,, x u, b 1,, b q, r 1,, r m ) (b 1,, b q ) is a foreign key referencing B b 1 not null,, b q not null } now prohibit null values for b 1 b q in A every entity in A is related to an entity in B b q y 1 Enforcing relational constraints Constraints must be satisfied at all times What happens when tuples in relations change? Action of changing a relation not part of basic relational model Database language implementing model enforces SQL commands changing relations: INSET, DELETE, UPDATE Domain constraints Don t allow attribute value not in domain Not null constraints Special case of domain constraints Candidate key constraints Can have other candidate keys declared as well as primary key Don t allow 2 nd tuple with same key value Implicit not null for attributes in a key Foreign key constraints Suppose Y denotes a set of attributes of relation B that reference the primary key of relation A. Don t allow tuple into B if no tuple in A with matching values for Y 5

Foreign key constraints continued suppose want to remove a tuple in A Suppose there is a tuple in B with matching values for Y Choices (in SQL): 1. Disallow deletion from A DELETE or UPDATE fails Choices (in SQL) continued: 2. ipple effect (CASCADE): emove tuple from A and all tuples from B with matching values for Y DELETE or UPDATE in A causes DELETE in B 3. Substitute value Put null (if Y not part of candidate key for B) or other default value for Y in B DELETE or UPDATE in A causes UPDATE in B Actions for board example? branches: (br_name, librarian, hours) Copies: (ISBN#, copy#, condition, purchase date, br_name) isbn# is a foreign key referencing books What about constraints not expressible in E model? Value-based constraints? General functional constraints? In relational model: Declaring and enforcing these depend on use of database language Use query semantics to check 6