The Data in a Relation To consider atomic data in relations; To consider data types in a relation; To consider missing data & NULLs in relations. Objectives.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

CIT 613: Relational Database Development using SQL Revision of Tables and Data Types.
Chapter 10: Designing Databases
Week 2: Directed Reading Relational Database Design Nick Rossiter
Joining Relations in SQL Objectives of the Lecture : To consider the Natural & Generalised Joins using the SQL1 standard; To consider the Natural & Generalised.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Referential Integrity & Foreign Keys Objectives of the Lecture : To consider Referential Integrity & Foreign Keys; To consider Referential Integrity Constraints.
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Candidate Keys Objectives of the Lecture : To consider Integrity Constraints; To consider the principles of Candidate Keys; To consider Candidate Keys.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Chapter 3 An Introduction to Relational Databases.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Objectives of the Lecture :
The Relational Model These slides are based on the slides of your text book.
Module Title? DBMS E-R Model to Relational Model.
Retrievals & Projections Objectives of the Lecture : To consider retrieval actions from a DB; To consider using relational algebra for defining relations;
Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model.
Chapter 3 An Introduction to Relational Databases.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
Introduction Objectives of the Lecture : To consider “What is a Database ?” To consider “What is a Relational Database ?” i.e. what is a “relation”, and.
The Relational Model1 Nulls A dilemma. The Relational Model2 The Real World Situation A common situation “Date of birth not given” “Present whereabouts.
Names Variables Type Checking Strong Typing Type Compatibility 1.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Ad Hoc Constraints Objectives of the Lecture : To consider Ad Hoc Constraints in principle; To consider Ad Hoc Constraints in SQL; To consider other aspects.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Amendments & Transactions Objectives of the Lecture : To consider amendments to a relation; To consider transactions in SQL.
NULLs & Outer Joins Objectives of the Lecture : To consider the use of NULLs in SQL. To consider Outer Join Operations, and their implementation in SQL.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Set Operations Objectives of the Lecture : To consider the Set Operations Union, Difference and Intersect; To consider how to use the Set Operations in.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
Chapter 5 Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.5-2 Topics in this Chapter Values vs. Variables Types vs. Representations.
What is a Relation ? To consider how Set Theory defines the structure of relations; To consider how relations can be exploited to provide the equivalent.
Further GroupBy & Extend Operations Objectives of the Lecture : To consider “whole relation” Grouping; To consider the SQL Grouping option Having; To consider.
Topics Related to Attribute Values Objectives of the Lecture : To consider sorting relations by attribute values. To consider Triggers and their use for.
Programming Fundamentals. Today’s Lecture The Conditional Operator Logical Operators Structures Enumerations.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Insert & Delete Objectives of the Lecture : To consider the insertion of tuples into a relation; To consider the deletion of tuples from a relation; To.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Restrictions Objectives of the Lecture : To consider the algebraic Restrict operator; To consider the Restrict operator and its comparators in SQL.
1 CS 430 Database Theory Winter 2005 Lecture 7: Designing a Database Logical Level.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1 Agenda TMA02 M876 Block 4. 2 Model of database development data requirements conceptual data model logical schema schema and database establishing requirements.
Introduction to Database Programming with Python Gary Stewart
Standards and Conventions
LIS 384K.11 Database-Management Principles and Applications
Other Kinds of Arrays Chapter 11
STRUCTURE OF PRESENTATION :
Spreadsheets, Modelling & Databases
Relational Database Design
Objectives of the Lecture :
CMSC-461 Database Management Systems
Presentation transcript:

The Data in a Relation To consider atomic data in relations; To consider data types in a relation; To consider missing data & NULLs in relations. Objectives of the Lecture :

The Information Principle l A relation contains only data values, i.e. facts. Each attribute-in-a-tuple contains just a single data value. l In particular there are no pointers or OIDs. Pointers point to variables (because they reference the storage location of the variable) and thus are different in nature to data values. l The reason for this principle is to keep relations simple. This principle was enunciated by E. F. Codd (the founder of relational DBs) but is still relevant today.

Atomic Data The data in one attribute of one tuple must be atomic. Example : in this EMPLOYEE relation there is only one value in each attribute-in-a-tuple M-S S M D 8M W EName Smith Mitchell Robson 8Blake Jones ENo E3 E5 E1 4E6 E Sal ,500 21,000 32, ,000 68,000 Definition : an atomic value is a single, indivisible value, not a composite value or a collection of values. This requirement maintains the inherent simplicity of relations, and is of great practical benefit.

Non-Atomic Data Example : a “relation” containing non-atomic data. Part Bicycle Frame Wheel Quantity Component Frame Wheel A-frame Handlebars Saddle Rim Axle Spoke These attributes contain non-atomic data (also sometimes called repeating data); but this attribute does contain atomic data.

Data Types Definition : a Data Type has a set of permissible values. l Each attribute value must be drawn from the set of permissible values of the data type specified for that attribute. l More than one attribute in a relation may draw its values from the same data type. CB A D Type A Type B Type C-D

Using Data Types : an Example Text(2) ENoENameM-SSal any Text { S‚ M, W, D } { No > 999 AND No < 100,000 } 111E3555Smith222S22212,500 22E5166X47/3544A44500 Too long, 3 characters. Wrong letter, not S, M, W or D. Too small, less than 999. OK ! Any text.

Data Types - continued l A data type was traditionally known as a domain. The term data type is prefered since it emphasises the inclusion of permissible operators as well as permissible values. l A data type needs logical representations for its values and operators. These are what the user uses. They become part of the logical model. l A data type needs physical representations for its values & executable code for each of its operators. These form the implementation of the logical model. Examples :- Number : +, -, , , ,  apply to all possible numbers. Text : length( ), sub( ), concat( ) apply to all possible texts. Definition : a Data Type has a set of permissible operators.

A Variety of Data Types l Commonly needed data types are Built-In, i.e. provided with the DBMS. Examples : Number, Text, (& usually Date). l Depending on the DBMS, it is also usually possible to add new data types. Examples : special graphics, pictures, audio, video. l These are often called User-Defined. Such types are often inherently large and complex, and their standards are not as well established as for traditional numeric and text data. Thus they usually require considerable work to create, and are usually bought from a specialist vendor.

Underlying & Specific Data Types When specifying an attribute‘s type, there are typically 2 stages : 1. Specify the general kind of data required, e.g. numbers, text, dates. This is the Underlying Type. 2. Specify that subset of it that the attribute values must be limited to, e.g. only the integer numbers 1.. 1,000. This is the Specific Type. It uses the same operators as the underlying type. Underlying Type Specific Type

Floating point is a physical storage format. SQL Data Types l SQL data types are often based on their physical storage. Examples : in Oracle SQL :- l Char(x) = text of exactly x bytes, i.e. x characters. l Varchar2(x) = variable length text of up to x characters/ bytes maximum. l Integer = Integer number of standard precision. l Number = Floating point number. SQL attributes/columns are assigned their types when the relation/table is created with the Create Table statement. Bytes are a unit of physical storage.

Create the EMPLOYEE relation :- Create Table EMPLOYEE ( ENoChar(2), ENameVarchar2(30), M-SChar(1) Check( M-S in (‘S’, ‘M’, ‘W’, ‘D’ ) ), SalNumber Check( Sal > 999 AND Sal < ) ) ; SQL : Example Parameters used to constrain the underlying type to the desired specific type. Underlying domain. Set comprehension applied via CHECK. Set enumeration applied via CHECK.

Missing Data l In the real world, data is not always available to put in the DB. l Reasons include the value being :  unknown  not available  not applicable  not yet known  undefined  to be announced  does not exist  not supplied  etc

Solutions to Missing Data l Use a special value to represent missing data. Example : ‘N/A’, ‘T.B.A.’ It gives the reason why the data is missing. The special value must have the same type as the data that is missing, so it can be stored with the data that is known. This requires no special facility from the DBMS, so it can be used with any DBMS. However it can be somewhat limiting : e.g. prevents ‘N/A’ being used in a numeric type. l Use NULL to represent missing data. NULL is the absence of a value. NULL  0NULL  ‘ ’ NULL is not a member of any type, because there is no value. Requires special support from the DBMS. SQL DBMSs provide this support. But which reason does it represent ? space

Comparisons where NULL arises l Let X be a numeric variable. Consider the comparison X = 3 Suppose X is NULL. Logically an error should arise. In fact SQL treats the NULL as representing an existing but unknown value, and so gives the truth value maybe. Rationale : We don’t know if X = 3 because X is NULL (= not available); even when the NULL in the DB is caused by the value not existing and it never being possible for it to exist ! l Let X and Y be numeric variables. Consider the comparison X = Y Suppose X and Y are both NULL. In SQL the result is maybe not true. Thus NULLs require 3 truth values - true, false and maybe.

2-Valued (Boolean) Logic l Normal Boolean logic only has the truth values true and false. l The result (or value) of any comparison will be true or false. l Thus the Boolean logic operators AND, OR and NOT can be used to combine comparisons, forming an expression. Example :- ( X = 3 AND Y 0 ) The value of this expression will be true or false, and can be derived if the values of X and Y are known. l The rules which the logic operators apply to their operands to yield a Boolean result are represented by the truth tables :-

3-Valued Logic l We still want to use logical expressions. Therefore AND, OR and NOT must be extended to cope with maybe. l This gives the following truth tables :-

SQL : Not NULL Constraint l Sometimes we want to prevent a column from ever holding NULLs. To achieve this in SQL, add a “Not NULL” constraint to the definition of the column. l Example :- Create Table EMPLOYEE ( EmpNoChar(2), ENameVarchar2(30) NOT NULL, M-SChar(1), SalNumber ) ; A name must always be provided.