In This Lecture. The Relational Model. The Relational Model. Relational Data Structure. Unnamed and named tuples. New thing:scheme (and attributes)

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

Relational Model Concepts

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

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

DBMS. Relational Model. Module Title?

Chapter 5. Relational Model Concepts 5/2/2008. Chapter Outline. Relational Database Constraints

Chapter 5. Relational Model Concepts 9/4/2012. Chapter Outline. The Relational Data Model and Relational Database Constraints

The Relational Model

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

In This Lecture. Normalisation to BCNF. Lossless decomposition. Normalisation so Far. Relational algebra reminder: product

Informatics 1: Data & Analysis

Physical DB Issues, Indexes, Query Optimisation. Database Systems Lecture 13 Natasha Alechina

In this Lecture. More SQL Data Definition. Deleting Tables. Creating Tables. ALTERing Columns. Changing Tables. More SQL

The Relational Data Model and Relational Database Constraints

01/01/2017. Chapter 5: The Relational Data Model and Relational Database Constraints: Outline. Chapter 5: Relational Database Constraints

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

The Relational Data Model. Data Model

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

Chapter 4. The Relational Model

Relational Model. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

Running Example Tables name location

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational

Chapter 5. The Relational Data Model and Relational Database Constraints. Slide 5-١. Copyright 2007 Ramez Elmasri and Shamkant B.

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 5-1

The Relational Model of Data (ii)

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

ER Model. Objectives (2/2) Electricite Du Laos (EDL) Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 1

Relational data model

Database Systems Relational Model. A.R. Hurson 323 CS Building

The Relational Model. Week 2

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

The data structures of the relational model Attributes and domains Relation schemas and database schemas

Databases 1. Daniel POP

In This Lecture. Yet More SQL SELECT ORDER BY. SQL SELECT Overview. ORDER BY Example. ORDER BY Example. Yet more SQL

CS 377 Database Systems

Informatics 1: Data & Analysis

The Relational Data Model (ALL the Vocabulary)

Part I: Structured Data

Let s briefly review important EER inheritance concepts

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

ER Modeling ER Diagram ID-Dependent and Weak Entities Pg 1

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

The Relational Model

begin [atomic] operation, operation, { commit rollback} end

CSE 132A Database Systems Principles

CS 2451 Database Systems: Relational Data Model

The Relational Model. Database Management Systems

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

Database Systems ( 資料庫系統 )

CS275 Intro to Databases

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

The Relational Model

Relational Databases Overview

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

The Relational Model. Chapter 3

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Database Applications (15-415)

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

ECE 650 Systems Programming & Engineering. Spring 2018

Relational Model. CS 377: Database Systems

Solved MCQ on fundamental of DBMS. Set-1

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

Chapter 2 Introduction to Relational Models

Relational model. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Chapter 3. The Relational Model. Database Systems p. 61/569

CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

Institute of Southern Punjab, Multan

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

Relational Data Model. Christopher Simpkins

Chapter 1 SQL and Data

CSC 742 Database Management Systems

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

RELATIONAL DATA MODEL

Database Systems. Course Administration

The Relational Model 2. Week 3

Introduction to Database Systems. The Relational Data Model

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

The Relational Data Model. Data Models. Relational vs Semistructured. Structure Operations - Constraints

Introduction to Database Systems. The Relational Data Model. Werner Nutt

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Database Management Systems. Chapter 3 Part 1

Databases. Jörg Endrullis. VU University Amsterdam

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Introduction to Relational Database Systems Fall 2016 Lecture 1

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

Relational Algebra Part I. CS 377: Database Systems

Transcription:

Database Systems Lecture 3 Natasha Alechina In This Lecture Relational data integrity For more information Connolly and Begg chapter 3 E.F. Codd s paper `A Relational Model of Data for Large Shared Data Banks a link from the module web page, ~nza/g51dbs07. Relational Data Structure Introduced in E.F. Codd s 1970 paper A Relational Model of Data for Large Shared Databanks The foundation for most (but not all) current database systems Concerned with 3 main things Data structure (how data is represented) Data integrity (what data is allowed) Data manipulation (what you can do with the data) Data is stored in relations (tables) Each relation has a scheme (heading) The scheme defines the relation s attributes (columns) Data takes the form of tuples (rows) New thing:scheme (and attributes) Before After Unnamed and named tuples A tuple is <John, 23> A tuple is {(Name,John), (Age,23)} 1 2 Just numbers of columns 1 2 Just numbers of columns 1

Not a big difference! Relational Data Structure There is no fundamental difference between named and unnamed perspectives on relations We could have written tuples <a,b,c> as sets of pairs {(1,a), (2,b),(3,c)}, only we know anyway in which order 1,2,3 go, so we can skip the numbers. Written as sets of pairs (partial functions), tuples can be written in any order, e.g. {(3,c),(2,b),(1,a)}. More formally - A scheme is a set of attributes A tuple assigns a value to each attribute in its scheme A relation is a set of tuples with the same scheme { { (Name, John), (Age, 23) }, { (Name, Mary), (Age, 20) }, { (Name, Mark), (Age, 18) }, { (Name, Jane), (Age, 21) } } Relations is {ID, Name, Salary, } are ID, Name, Salary, and Degree is 4 ID Name Salary M139 John Smith 18,000 Marketing M140 Mary Jones 22,000 Marketing A368 Jane Brown 22,000 Accounts P222 Mark Brown 24,000 Personnel A367 David Jones 20,000 Accounts, e.g. { (ID, A368), (Name, Jane Brown), (Salary, 22,000), (, Accounts) } Cardinality is 5 Relational Data Integrity Data integrity controls what data can be in a relation Domains restrict the possible values a tuple can assign to each attribute Candidate and Primary Keys identify tuples within a relation Foreign Keys link relations to each other and Domains Candidate Keys A domain is given for each attribute The domain lists the possible values for that attribute Each tuple assigns a value to each attribute from its domain Examples An age might have to come from the set of integers between 0 and 150 A department might come from a given list of strings A notes field might allow any string at all A set of attributes in a relation is called a candidate key if, and only if, Every tuple has a unique value for the set of attributes (uniqueness) No proper subset of the set has the uniqueness property (minimality) ID First Last S139 John Smith S140 Mary Jones S141 John Brown S142 Jane Smith Candidate key: {ID}; {First,Last} looks plausible but we may get people with the same name {ID, First}, {ID, Last} and {ID, First, Last} satisfy uniqueness, but are not minimal {First} and {Last} do not give a unique identifier for each row 2

Choosing Candidate Keys Important: don t look just on the data in the table to determine what is a candidate key The table may contain just one tuple, so anything would do! Primary Keys One Candidate Key is usually chosen to be used to identify tuples in a relation This is called the Primary Key Often a special ID attribute is used as the Primary Key Use knowledge of the real world what is going to stay unique! NULLs and Primary Keys Foreign Keys Missing information can be represented using NULLs A NULL indicates a missing or unknown value More on this later... Entity Integrity: Primary Keys cannot contain NULL values Foreign Keys are used to link data in two relations. A set of attributes in the first (referencing) relation is a Foreign Key if its value always either Matches a Candidate Key value in the second (referenced) relation, or Is wholly NULL This is called Referential Integrity Foreign Keys - Example Foreign Keys - Example {DID} is a Candidate Key for - Each entry has a unique value for DID {DID} is a Foreign Key in - each s DID value is either NULL, or matches an entry in the relation. This links each to (at most) one ID Name Manager E1496 John Smith E1499 E1497 Mary Brown E1498 E1498 Mark Jones E1499 E1499 Jane Smith NULL {ID} is a Candidate Key for, and {Manager} is a Foreign Key, which refers to the same relation - every tuple s Manager value is either NULL or matches an ID value 3

Referential Integrity When relations are updated, referential integrity can be violated This usually occurs when a referenced tuple is updated or deleted There are a number of options: RESTRICT - stop the user from doing it CASCADE - let the changes flow on NULLIFY - make values NULL Referential Integrity - Example What happens if Marketing s DID is changed to 16 in? The entry for Accounts is deleted from? RESTRICT CASCADE RESTRICT stops any action that violates integrity You cannot update or delete Marketing or Accounts You can change Personnel as it is not referenced CASCADE allows the changes made to flow through If Marketing s DID is changed to 16 in, then the DIDs for John Smith and Mark Jones also change If Accounts is deleted then so is Mary Brown 13 16 Marketing 16 16 NULLIFY Naming Conventions NULLIFY sets problem values to NULL If Marketing s DID changes then John Smith s and Mark Jones DIDs are set to NULL If Accounts is deleted, Mary Brown s DID becomes NULL 13 16 Marketing NULL NULL NULL Naming conventions A consistent naming convention can help to remind you of the structure Assign each table a unique prefix, so a student name may be stuname, and a module name modname Naming keys Having a unique number as the primary key can be useful If the table prefix is abc, call this abcid A foreign key to this table is then also called abcid 4

Example Next Lecture Student stuid stuname the Student table Enrolment stuid modid tables other than Enrolment Module modid modname the Module table Entity/Relationship models Entities and Relationships and Cardinality Ratios E/R Diagrams For more information Connolly and Begg chapter 11. Ullman and Widom chapter 2. 5