CSEN 501 CSEN501 - Databases I

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

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

EECS 647: Introduction to Database Systems

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

The Relational Model. Why Study the Relational Model?

3. Relational Model and Relational Algebra

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

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

Database Systems. Lecture 1: Introduction

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

The Relational Data Model: Structure

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

Lecture 6. SQL, Logical DB Design

SQL NULL s, Constraints, Triggers

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

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

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

Database Management Systems. Chapter 1

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

The Entity-Relationship Model

Relational Database Basics Review

The Relational Data Model and Relational Database Constraints

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

2. Basic Relational Data Model

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

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Databases and BigData

Introduction to Databases

Fundamentals of Database Design

CSE 233. Database System Overview

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

Databases What the Specification Says

Data Modeling. Database Systems: The Complete Book Ch ,

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

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

Overview. Introduction to Database Systems. Motivation... Motivation: how do we store lots of data?

Logical Schema Design: The Relational Data Model

Relational Databases

How To Create A Table In Sql (Ahem)

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

TIM 50 - Business Information Systems

Relational Database Concepts


Entity Relationship Diagram

BCA. Database Management System

Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??

COMP5138 Relational Database Management Systems. Databases are Everywhere!

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

Review: Participation Constraints

Oracle Database 10g Express

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

IT2305 Database Systems I (Compulsory)

Course: CSC 222 Database Design and Management I (3 credits Compulsory)

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

CSE 132A. Database Systems Principles

Lesson 8: Introduction to Databases E-R Data Modeling

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

Answers included WORKSHEET: INTEGRITY CONTROL IN RELATIONAL DATABASES

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

Concepts of Database Management Seventh Edition. Chapter 6 Database Design 2: Design Method

Relational Databases. Christopher Simpkins

How To Manage Data In A Database System

Exercise 1: Relational Model

Foundations of Information Management

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

Basic Concepts of Database Systems

The core theory of relational databases. Bibliography

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

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

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

Database Design Methodology

Tutorial on Relational Database Design

CPS352 Database Systems: Design Project

Section of DBMS Selection & Evaluation Questionnaire

Topics. Introduction to Database Management System. What Is a DBMS? DBMS Types

Entity-Relationship Model

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

Winter Winter

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

Databases. DSIC. Academic Year

IT2304: Database Systems 1 (DBS 1)

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. COURSE CURRICULUM COURSE TITLE: DATABASE MANAGEMENT (Code: ) Information Technology

SQL Tables, Keys, Views, Indexes

Database Design. Adrienne Watt. Port Moody

Rose Data Modeler (logical)

ECS 165A: Introduction to Database Systems

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

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

David M. Kroenke and David J. Auer Database Processing 11 th Edition Fundamentals, Design, and Implementation. Chapter Objectives

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

A Little Set Theory (Never Hurt Anybody)

Database Design and Programming

Instant SQL Programming

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

Information Systems Modelling Information Systems I: Databases

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

Relational Data Analysis I

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

Introduction to Database Systems. Module 1, Lecture 1. Instructor: Raghu Ramakrishnan UW-Madison

Transcription:

CSEN501 - Databases I Lecture 3: The Relational Model Prof. Dr. Slim slim.abdennadher@guc.edu.eg German University Cairo, Faculty of Media Engineering and Technology

Design Steps Ideas E/R Design Relational Schema Relational DBMS

The Relational Data Model (1970) Lessons from the Codd paper: A Relational Model for Data for Large Shared Data Banks Let us separate physical level from conceptual level Model the data independently from how it will be used (accessed, printed, etc.) Describe the data mathematically A relation describes an association between data items - tuples with attributes We generally think of tables and rows, but that s somewhat imprecise Use standard mathematical (logical) operations over the data - these are the relational algebra or relational calculus

Why Did It Take So Many Years to Implement RDs? Codd s original work: 1969-70 Earliest relational database research: 1976 System R developed by IBM researchers during the late 1970s. Oracle developed in 1979 using many of the System R results Why the gap? You could do the same thing in other ways Nobody wants to write math formulas Why would I turn my data into tables? It won t perform well

Getting More Concrete: Building a Database and Application Start with a conceptual model On paper using certain techniques, e.g. E/R diagrams We ignore low-level details - focus on logical representation Design and implement schema Design and codify (in SQL) the relations Think about the physical level - indexes, etc. Import the data Write applications using DBMS and other tools Many of the hard problems are taken care of by other people (DBMS, API writers, library authors, web server, etc.)

Conceptual Design for a University Database

What is a Relational Database? The relational model is based on the concept of a relation. A relation is physically represented as a table or two-dimensional array. Tables are used to hold information about objects to be represented in the database. Using the terms of EER model, both entity sets and relationships sets are shown using tables. Student: sid firstname gpa 1 Dina 1.0 2 Ahmed 2.0 3 Maria 0.7 sid Enroll: grade cid 1 A 501 1 A 502 3 C 401 Our focus now is the relational schema: set of tables Can have other kinds of schemas - XML, object,... Question: Can a table have duplicate rows? Course: cid subj sem 501 DB W05 502 TC W05 401 CP S05

Some Terminology I A relation is represented as a two-dimensional table with columns and rows. Columns are called attributes or fields. The number of these columns is the arity (degree) of the relation The rows are called tuples. The number of rows is called cardinality. Each attribute has values taken from a domain, e.g., subj has domain string Domains: string, integer, real, date,... - atomic types Theoretically: a relation is a set of tuples; no tuple can occur more than once Mathematicians define a relation to be a subset of a Cartesian product of a list of domains. Example D 1 = {1, 2} and D 2 = {a, b, c} D 1 D 2 = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}

Some Terminology II What are the cardinality and arity of relation Student? Student sid firstname gpa 1 Dina 1.0 2 Ahmed 2.0 3 Maria 0.7 4 Ali 1.3 Can we put a Student tuple and a Course tuple in the same relation? If not how to prevent this? In other words, how to describe relations?

Describing Relations A relation is defined by a schema, which specifies domains of each field in the relation. In DBMS, data definition language (DDL) is used - like programming language type definitions In relational DBs, we use relation(attribute:domain) Student(sid:int, name:string, gpa:real) Enroll(sid:int, grade:string, cid:string) Course(cid:string, subj:string, sem:string) Teaches(fid:int, cid:string) Professor(fid:int, name:string) Database people, when they are discussing design, often assume domains are evident to the reader: Student(sid, name, gpa)

Definitions: Schema, Relational database A relation (instance) is a table (a set of tuples). A schema is the structure of the table together with a specification of the domains and any other restrictions on possible values. A (relational) database schema is a collection of schemas. A relational database (instance) is a collection of tables, each has a distinct name.

Integrity Constraints (ICs) Integrity Constraint (IC): condition that must be true for any instance of the database. Example: a schema specifies domains of the fields in the relation, and is called domain constraints. ICs are specified when schema is defined. Note: this might not be true in Web databases. ICs are checked when relations are modified. A legal instance of relation is one that satisfies all specific ICs. DBMS does not allow illegal instances. If the DBMS checks ICs, stored data is more faithful to real world meaning, that is, for consistency and accuracy. When ICs are enforced, DBMS also avoids data entry errors.

Key Constraints: Entity Integrity A set of fields is a (candidate) key for a relation if no two distinct tuples can have the same values in all key fields, any proper subset of the key does not satisfy this condition. If a set of fields satisfies condition 1 but does not satisfy condition 2, then it is called a super key for the relation. If there are more than one candidate keys for a relation, one is chosen to be the primary key. Given a relation schema, the primary keys of the schema is underlined. Student(sid:int, name:string, gpa:real) Entity Integrity: in a relation no attribute of a primary key can have a null value.

Key Constraints: Foreign Key Constraint Foreign key: A set of fields in one relation that is used to refer to a tuple in another relation. This set must correspond to the primary key of the second relation. Example: sid is a foreign key in Enroll referring to Student Student(sid:int, name:string, gpa:real) Enroll(sid:int, grade:string, cid:string) ------- Foreign key constraints: Let S 1 be a foreign key in relation R 1 referring to R 2. Then the values of S 1 in R 1 must match (be a subset of) the values of S 1 in R 2.

Foreign Keys - Referential Integrity Question: Does the following satisfy the foreign key constraint? Student: sid firstname gpa 1 Dina 1.0 2 Ahmed 2.3 3 Maria 0.7 Enroll: sid grade cid 1 A 501 1 A 502 5 C 202 Referential Integrity: the database does not include any invalid foreign key value. That is, all foreign key constraints are enforced. Suppose Table B has a foreign key that points to a field in Table A. Referential integrity would prevent you from adding a record to Table B that does not exist in Table A. The referential integrity rules might also specify that whenever you delete a record from Table A, any records in Table B that are linked to the deleted record will also be deleted. This is called cascading delete.

Representing Relational Database Schemas A relational database schema can have any number of relations. Relation schemas can be represented by giving the name of each relation followed by the attribute names in parentheses with the primary key underlined. The clearest way of showing foreign keys is by drawing arrows from the foreign keys to the primary keys they refer to. Some attributes appear in more than one relation. Student(studID, lastname, firstname, major) Enroll(studID,classNo,grade) To distinguish between the two appearances of attributes, we use the relation name followed by a period followed by the attribute name. Student.studID Enroll.studID When an attribute appears in more than one relation, its appearance usually represents a relationship or interaction between tuples of the two relations. Common attributes play important role in data manipulation.

Relational Data Manipulation Languages Variety languages used by relational database management systems Procedural languages: The user tells the system how to manipulate the data, e.g. Relational Algebra Declarative languages: the user states what data is needed but not exactly how it is to be located, e.g. Relational Calculus and SQL Graphical languages: allowing the user to give an example or an illustration of what data should be found, e.g. QBE

Summary - What you should remember! What is a relational database? Tuple? Attribute? Field? Domain? Schema? Database schema? Instance? What are integrity constraints? Why study them? How to decide whether an instance is legal? Where do ICs come from? What integrity constraints are a must for relational databases? Questions: Are the following claims correct? Every relation has at least one key. Every relation has one and only one primary key. Every relation has one and only one superkey.