1 Relational Data Model CS 157B Nidhi Patel. 2 What is a Data Model? A notation for describing data or information A notation for describing data or information.

Slides:



Advertisements
Similar presentations
Chapter 3 : Relational Model
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Design -- Basic SQL
1 Lecture 11: Basic SQL, Integrity constraints
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
D ATABASE S YSTEMS I T HE R ELATIONAL D ATA M ODEL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Movies length titleyearfilmType Voices isa Cartoons isa MurderMystery weapon toStar Our Movie Example.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
13.5 Representing Data Elements Fields, Records, Blocks Variable-length Data Modifying Records.
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
Correlated Queries SELECT title FROM Movie AS Old WHERE year < ANY (SELECT year FROM Movie WHERE title = Old.title); Movie (title, year, director, length)
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
The Relational Model These slides are based on the slides of your text book.
Data Models Amandeep Kaur Lecturer GPC Khunimajra Call at
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
ORDBS1 Object Relational Database Systems: 1. Introduction 2. Objects in SQL3 3. Comparison of ODL/OQL and SQL3 Approaches CIS 671.
Relational Model 2015, Fall Pusan National University Ki-Joune Li.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
1 The Relational Model Instructor: Mohamed Eltabakh
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Relational Algebra Spring 2012 Instructor: Hassan Khosravi.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
1 Chapter 6 Constraints uForeign Keys uConstraints.
Lu Chaojun, SJTU Relational Data Model 1. Lu Chaojun, SJTU What’s a Data Model? A notation (collection of conceptual tools) for describing data as seen.
1 More SQL uDatabase Modification uDefining a Database Schema uViews.
CS 338The Relational Model2-1 The Relational Model Lecture Topics Overview of SQL Underlying relational model Relational database structure SQL DDL and.
Advanced SQL Concepts - Checking of Constraints CIS 4301 Lecture Notes Lecture /6/2006.
© D. Wong Normalization  Purpose: process to eliminate redundancy in relations due to functional or multi-valued dependencies.  Decompose relation.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
CS 157B Database Systems Dr. T Y Lin. Updates 1.Red color denotes updated data (ppt) 2.Class participation will be part of “extra” credits to to “quiz.
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)
Dr. T. Y. Lin | SJSU | CS 157A | Fall 2011 Chapter 2 THE RELATIONAL MODEL OF DATA 1.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
1 Chapter 6 More SQL uDatabase Modification uDefining a Database Schema uViews.
SQL Exercises – Part I April
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
Jennifer Widom Relational Databases The Relational Model.
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
CS 157B Database Systems Dr. T Y Lin. 1.2 Overview of a Database Management System Data-Definition Language Commands –Illustrated by three examples.
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 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
Relational Data Model Lu Chaojun, SJTU.
Introduction to Structured Query Language (SQL)
THE RELATIONAL MODEL OF DATA
Chap 2. The Relational Model of Data
THE RELATIONAL MODEL OF DATA
Relational Databases The Relational Model.
Relational Databases The Relational Model.
SQL OVERVIEW DEFINING A SCHEMA
2018, Fall Pusan National University Ki-Joune Li
Defining a Database Schema
CMSC-461 Database Management Systems
SQL (Structured Query Language)
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

1 Relational Data Model CS 157B Nidhi Patel

2 What is a Data Model? A notation for describing data or information A notation for describing data or information Description consists of 3 parts: Description consists of 3 parts: 1) Structure of the data -Arrays and structures or objects 2) Operations on the data -Queries (Operations that retrieve information) information) -Modifications (Operations that change the database) database) 3) Constraints on the data -Limitations

3 Important Data Models 1) The relational model (including object- relational extensions) -Present in all commercial database management systems 2) The semistructured-data model (including XML and related standards)

4 The Relational Model Based on tables Based on tables The structure portion resemble an array of structs in C The structure portion resemble an array of structs in C Column headers  Field names Column headers  Field names Each row  values of struct in the array Each row  values of struct in the array

5 An example relation TitleYearLengthGenre Gone With the Wind Drama Star Wars sciFi Wayne’s World comedy

6 The Semistructured Model Semistructured data resembles trees or graphs Semistructured data resembles trees or graphs Represent data by hierarchically nested tagged elements Represent data by hierarchically nested tagged elements The tags are similar to those used in HTML The tags are similar to those used in HTML Tags define the role played by different pieces of data Tags define the role played by different pieces of data

7 Movie data as XML <Movies> <Year>1939</Year><Length>231</Length><Genre>drama</Genre></Movies> <Year>1977</Year><Length>124</Length><Genre>sciFi</Genre></Movies> <Year>1992</Year><Length>95</Length><Genre>comedy</Genre> </Movies>

8 Other Data Models Object-oriented features Object-oriented features -Values can have structure -Relations can have associated methods Object-relational model --- which are analogous to the way structs in C were extended to objects in C++

9 Comparison of Modeling Approaches Semistructured models have more flexibility than relations Semistructured models have more flexibility than relations Nevertheless, the relational model is still preferred Nevertheless, the relational model is still preferred Because database are large, Because database are large, -efficiency of access to data -efficiency of modifications to data -ease of use These all goals can be achieved with a model, particularly the relational model These all goals can be achieved with a model, particularly the relational model

10 Comparison of Modeling Approaches Relational model provides Relational model provides - A simple, limited approach to structuring data, yet is reasonably flexible so anything data, yet is reasonably flexible so anything can be modeled can be modeled - A limited, yet useful, collection of operations on data operations on data

11 Basics of the Relational Model Represent data as a two-dimensional table called a relation Represent data as a two-dimensional table called a relation

12 Basics of the Relational Model Domain: a particular elementary type Domain: a particular elementary type For example: integer, string For example: integer, string Movies (title:string, year:integer, length:integer, genre:string) length:integer, genre:string)

13 Keys of Relations A set of attributes forms a key for a relation, if we don’t allow two tuples in a relation instance to have the same values in all the attributes of the key A set of attributes forms a key for a relation, if we don’t allow two tuples in a relation instance to have the same values in all the attributes of the key Relation Movies has a key consisting of the two attributes title and year Relation Movies has a key consisting of the two attributes title and year Attribute or attributes that form a key for a relation by underlining the key attribute(s). Attribute or attributes that form a key for a relation by underlining the key attribute(s). Movies (title, year, length, genre)

14 Defining a Relation Schema in SQL SQL (pronounced “sequel”) is the principal language used to describe and manipulate relational databases SQL (pronounced “sequel”) is the principal language used to describe and manipulate relational databases Two aspects to SQL Two aspects to SQL 1) Data-Definition  for declaring database schemas database schemas 2) Data-Manipulation  for querying and modifying database modifying database

15 Relations in SQL SQL makes difference between 3 kinds of relations: SQL makes difference between 3 kinds of relations: - Stored relations  tables - Views - Temporary tables

16 Data Types All attributes must have a data type All attributes must have a data type 1) Character strings of fixed or varying length length CHAR(n)  a fixed-length string of up to n characters to n charactersOR VARCHAR (n)

17 Data Types 2) Bit strings of fixed or varying length BIT(n)  bit strings of length n BIT VARYING(n)  bit strings of length up to n up to n 3) The type BOOLEAN denotes an attribute whose value is logical - The possible values are TRUE, FALSE, and UNKNOWN FALSE, and UNKNOWN

18 Data Types 4) The type INT or INTEGER denotes typical integer values integer values - The type SHORTINT also denotes integers, but the number of bits permitted may be less depending on number of bits permitted may be less depending on the implementation the implementation 5) The type FLOAT denotes floating-point numbers - Real numbers with a fixed decimal point - DECIMAL (n,d) allows values that consist of n decimal digits, with the decimal point assumed to decimal digits, with the decimal point assumed to be d positions from the right be d positions from the right

19 Data Types 6) Dates and times can be represented by the data types DATE and TIME respectively

20 Simple Table Declarations CREATE TABLE Movies ( titleCHAR(100), yearINT, lengthINT, genreCHAR(10), studioNameCHAR(30), producerC#INT );

21 Modifying Relation Schemas ALTER TABLE MovieStar ADD phone CHAR(16); ALTER TABLE MovieStar ADD phone CHAR(16); ALTER TABLE MovieStar DROP birthdate; ALTER TABLE MovieStar DROP birthdate;

22 Default Values gender CHAR(1) DEFAULT ‘?’, gender CHAR(1) DEFAULT ‘?’, birthdate DATE DEFAULT DATE ‘ ’ ALTER TABLE MovieStar ADD phone CHAR(16) DEFAULT ‘unlisted’; ALTER TABLE MovieStar ADD phone CHAR(16) DEFAULT ‘unlisted’;

23 Declaring Primary Keys CREATE TABLE MovieStar ( CREATE TABLE MovieStar ( nameCHAR(30), address VARCHAR(255), gender CHAR(1), birthdate DATE, PRIMARY KEY (name) ); );

24 Declaring Foreign Keys Example: Suppose we wish to declare the relation Studio (name, address, presC#) Whose primary key is name and which has a foreign key presC# that references cert# of relation MovieExec (name, address, cert#, netWorth) Solution: CREATE TABLE Studio ( name CHAR(30) PRIMARY KEY, name CHAR(30) PRIMARY KEY, address VARCHAR(255), address VARCHAR(255), presC# INT, presC# INT, FOREIGN KEY (presC#) REFERENCES FOREIGN KEY (presC#) REFERENCES MovieExec (cert#) MovieExec (cert#)

25 Adding and Deleting Tuples Insert a single tuple using: Insert a single tuple using: INSERT INTO StarsIn VALUES (‘The Maltese Falcon’, 1942, ‘Sydney Greenstreet’); Delete all tuples satisfying some condition: Delete all tuples satisfying some condition: DELETE FROM StarsIn WHERE movieTitle = ‘The Maltese Falcon’ AND movie Year = 1942 AND movie Year = 1942 AND starName = ‘Sydney Greenstreet’; starName = ‘Sydney Greenstreet’;

26 Relational Data Model It is almost impossible to store a huge amount of data without proper manage. It is almost impossible to store a huge amount of data without proper manage. To manage and store data, many methods and models have been developed. To manage and store data, many methods and models have been developed. Relational Database Model, which has proved to be the best data management model. Relational Database Model, which has proved to be the best data management model.

27 Invented by Relational data model was invented by Edgar F. Codd Relational data model was invented by Edgar F. Codd Subsequently maintained and developed by Chris Date and Hugh Darwen among others Subsequently maintained and developed by Chris Date and Hugh Darwen among others The relational data model is based on the predicate logic and set theory of mathematics. The relational data model is based on the predicate logic and set theory of mathematics. Codd used mathematical n-ary relations as a base to represent data, which is a subset of the Cartesian product of n sets. Codd used mathematical n-ary relations as a base to represent data, which is a subset of the Cartesian product of n sets. Codd Date

28 Summary Data Models Data Models Relational Model Relational Model Schemas Schemas Keys Keys Semistructured Data Model Semistructured Data Model SQL SQL Data Definition Data Definition Altering Schemas Altering Schemas