CSCI3030U Database Models

Similar documents
CS145 Introduction. About CS145 Relational Model, Schemas, SQL Semistructured Model, XML

Chapter 2 The relational Model of data. Relational model introduction

Relational Data Model is quite rigid. powerful, but rigid.

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE

SQL DATA DEFINITION LANGUAGE

SQL: Data Definition Language

XML. Document Type Definitions. Database Systems and Concepts, CSCI 3030U, UOIT, Course Instructor: Jarek Szlichta

Databases-1 Lecture-01. Introduction, Relational Algebra

Databases 1. Defining Tables, Constraints

Introduction to SQL. Multirelation Queries Subqueries. Slides are reused by the approval of Jeffrey Ullman s

Introduction to SQL. Select-From-Where Statements Multirelation Queries Subqueries. Slides are reused by the approval of Jeffrey Ullman s

XML. Document Type Definitions XML Schema. Database Systems and Concepts, CSCI 3030U, UOIT, Course Instructor: Jarek Szlichta

Introduction to SQL. Select-From-Where Statements Multirelation Queries Subqueries

Introduction to SQL SELECT-FROM-WHERE STATEMENTS SUBQUERIES DATABASE SYSTEMS AND CONCEPTS, CSCI 3030U, UOIT, COURSE INSTRUCTOR: JAREK SZLICHTA

SQL Continued! Outerjoins, Aggregations, Grouping, Data Modification

CS 317/387. A Relation is a Table. Schemas. Towards SQL - Relational Algebra. name manf Winterbrew Pete s Bud Lite Anheuser-Busch Beers

Chapter 6 The database Language SQL as a tutorial

Semistructured data, XML, DTDs

Chapter 6 The database Language SQL as a tutorial

EXTENDED RELATIONAL ALGEBRA OUTERJOINS, GROUPING/AGGREGATION INSERT/DELETE/UPDATE

Constraints. Local and Global Constraints Triggers

More SQL. Extended Relational Algebra Outerjoins, Grouping/Aggregation Insert/Delete/Update

SQL: Data Manipulation Language

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

Introduction to Database Systems CSE 414

ODL Design to Relational Designs Object-Relational Database Systems (ORDBS) Extensible Markup Language (XML)

Query Languages for XML

CS54100: Database Systems

Relational Algebra and SQL. Basic Operations Algebra of Bags

Why SQL? SQL is a very-high-level language. Database management system figures out best way to execute query

Constraints and Triggers

Views, Indexes, Authorization. Views. Views 8/6/18. Virtual and Materialized Views Speeding Accesses to Data Grant/Revoke Priviledges

user specifies what is wanted, not how to find it

XQUERY: an XML Query Language

The Relational Model

Beersèname, manfè. Likesèdrinker, beerè. Sellsèbar, beer, priceè. Frequentsèdrinker, barè

Chapter 1: Introduction

Subqueries. Must use a tuple-variable to name tuples of the result

e e Conceptual design begins with the collection of requirements and results needed from the database (ER Diag.)

Introduction to Database Systems CSE 414

Entity-Relationship Model. Purpose of E/R Model

Relational Algebra. Algebra of Bags

Relational Algebra BASIC OPERATIONS DATABASE SYSTEMS AND CONCEPTS, CSCI 3030U, UOIT, COURSE INSTRUCTOR: JAREK SZLICHTA

10/24/12. What We Have Learned So Far. XML Outline. Where We are Going Next. XML vs Relational. What is XML? Introduction to Data Management CSE 344

Introduction to Data Management CSE 344

Transactions, Views, Indexes. Controlling Concurrent Behavior Virtual and Materialized Views Speeding Accesses to Data

A tuple is dangling if it doesn't join with any

EMERGING TECHNOLOGIES. XML Documents and Schemas for XML documents

Answer Key for Exam II Computer Science 420 Dr. St. John Lehman College City University of New York 18 April 2002

Chapter 13 XML: Extensible Markup Language

Chapter 2 The relational Model of data. Relational algebra

CSC 343 Winter SQL: Aggregation, Joins, and Triggers MICHAEL LIUT

Database Design and Programming

Semistructured Data and XML

COMP.3090/3100 Database I & II. Textbook

From E/R Diagrams to Relations

Relational Query Languages

CS54100: Database Systems

Introduction to Semistructured Data and XML. Overview. How the Web is Today. Based on slides by Dan Suciu University of Washington

SQL. The Basics Advanced Manipulation Constraints Authorization 1. 1

Overview. Structured Data. The Structure of Data. Semi-Structured Data Introduction to XML Querying XML Documents. CMPUT 391: XML and Querying XML

Introduction to Database Systems CSE 444

CS425 Fall 2016 Boris Glavic Chapter 1: Introduction

1 Relational Data Model

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Most database operations involve On- Line Transaction Processing (OTLP).

Database Technology Introduction. Heiko Paulheim

Introduction to XML. XML: basic elements

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

Introduction to XML Zdeněk Žabokrtský, Rudolf Rosa

Data Presentation and Markup Languages

CSCD43: Database Systems Technology. Lecture 4

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

Chapter 1: Introduction

Overview. Introduction. Introduction XML XML. Lecture 16 Introduction to XML. Boriana Koleva Room: C54

CS143: Relational Model

Introduction to XML. Yanlei Diao UMass Amherst April 17, Slides Courtesy of Ramakrishnan & Gehrke, Dan Suciu, Zack Ives and Gerome Miklau.

Chapter 1: Introduction. Chapter 1: Introduction

HTML vs. XML In the case of HTML, browsers have been taught how to ignore invalid HTML such as the <mymadeuptag> element and generally do their best

On-Line Application Processing

Relational Algebra. Spring 2012 Instructor: Hassan Khosravi

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

Introduction to Semistructured Data and XML. Contents

Additional Readings on XPath/XQuery Main source on XML, but hard to read:

Part 2: XML and Data Management Chapter 6: Overview of XML

CS411 Database Systems. 04: Relational Algebra Ch 2.4, 5.1

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

Data Formats and APIs

CLASS DISCUSSION AND NOTES

Programming and Database Fundamentals for Data Scientists

I Relational Database Modeling how to define

Parallel/Distributed Databases XML

CMPT 354 Database Systems I. Spring 2012 Instructor: Hassan Khosravi

Announcements. JSon Data Structures. JSon Syntax. JSon Semantics: a Tree! JSon Primitive Datatypes. Introduction to Database Systems CSE 414

Design Techniques. 1. Avoid redundancy 2. Limit the use of weak entity sets 3. Don t use an entity set when an attribute will do

Running Example Tables name location

Administrivia. CS 235: Introduction to Databases. Examples. What is a DBMS? The DBMS Marketplace. Relational Model

Transcription:

CSCI3030U Database Models CSCI3030U RELATIONAL MODEL SEMISTRUCTURED MODEL 1

Content Design of databases. relational model, semistructured model. Database programming. SQL, XPath, XQuery. Not DBMS implementation. 2

Do You Know SQL? Explain the difference between: SELECT b FROM R WHERE a<10 OR a>=10; and SELECT b FROM R; a b 5 20 10 30 20 40 Table R 3

And How About These? SELECT a FROM R, S WHERE R.b = S.b; SELECT a FROM R WHERE b IN (SELECT b FROM S); 4

Interesting Stuff About Databases It used to be about boring stuff: employee records, bank records, etc. Today, the field covers all the largest sources of data, with many new ideas. Web search. Data mining. Scientific and medical databases. Integrating information. 5

More Interesting Stuff Database programming centers around limited programming languages. Leads to very succinct programming, but also to unique query-optimization problems. 6

Still More You may not notice it, but databases are behind almost everything you do on the Web. Google searches. Queries at Amazon, ebay, etc. 7

And More Databases often have unique concurrency-control problems Many activities (transactions) at the database at all times. Must not confuse actions, e.g., two withdrawals from the same account must each debit the account. 8

What is a Data Model? 1. Mathematical representation of data. Examples: relational model = tables; semistructured model = trees/graphs. 2. Operations on data. 3. Constraints. 9

A Relation is a Table Attributes (column headers) Tuples (rows) name Winterbrew Bud Lite manf Pete s Anheuser-busch Relation name Beers 10

Schemas Relation schema = relation name and attribute list. Optionally: types of attributes. Example: Beers(name, manf) or Beers(name: string, manf: string) Database = collection of relations. Database schema = set of all relation schemas in the database. 11

Why Relations? Very simple model. Often matches how we think about data. Abstract model that underlies SQL, the most important database language today. 12

Our Running Example Beers(name, manf) Bars(name, addr, license) Drinkers(name, addr, phone) Likes(drinker, beer) Sells(bar, beer, price) Frequents(drinker, bar) Underline = key (tuples cannot have the same value in all key attributes). Excellent example of a constraint. 13

Database Schemas in SQL SQL is primarily a query language, for getting information from a database. But SQL also includes a data-definition component for describing database schemas. 14

Creating (Declaring) a Relation Simplest form is: CREATE TABLE <name> ( <list of elements> ); To delete a relation: DROP TABLE <name>; 15

Elements of Table Declarations Most basic element: an attribute and its type. The most common types are: INT or INTEGER (synonyms). REAL or FLOAT (synonyms). CHAR(n ) = fixed-length string of n characters. VARCHAR(n ) = variable-length string of up to n characters. 16

Example: Create Table CREATE TABLE Sells ( bar CHAR(20), beer VARCHAR(20), price REAL ); 17

SQL Values Integers and reals are represented as you would expect. Strings are too, except they require single quotes in many database engines. Two single quotes = real quote, e.g., Joe s Bar. Any value can be NULL. 18

Dates and Times DATE and TIME are types in SQL. The form of a date value is: DATE yyyy-mm-dd Example: DATE 2007-09-30 for Sept. 30, 2007. 19

Times as Values The form of a time value is: TIME hh:mm:ss with an optional decimal point and fractions of a second following. Example: TIME 15:30:02.5 = two and a half seconds after 3:30PM. 20

Declaring Keys An attribute or list of attributes may be declared PRIMARY KEY or UNIQUE. Either says that no two tuples of the relation may agree in all the attribute(s) on the list. There are a few distinctions to be mentioned later. 21

Declaring Single-Attribute Keys Place PRIMARY KEY or UNIQUE after the type in the declaration of the attribute. Example: CREATE TABLE Beers ( ); name manf CHAR(20) UNIQUE, CHAR(20) 22

Declaring Multiattribute Keys A key declaration can also be another element in the list of elements of a CREATE TABLE statement. This form is essential if the key consists of more than one attribute. May be used even for one-attribute keys. 23

Example: Multiattribute Key The bar and beer together are the key for Sells: CREATE TABLE Sells ( bar CHAR(20), beer VARCHAR(20), price REAL, PRIMARY KEY (bar, beer) ); 24

PRIMARY KEY vs. UNIQUE 1. There can be only one PRIMARY KEY for a relation, but several UNIQUE attributes. 2. No attribute of a PRIMARY KEY can ever be NULL in any tuple. But attributes declared UNIQUE may have NULL s, and there may be several tuples with NULL. 25

Semistructured Data Another data model, based on trees and graphs. Motivation: flexible representation of data. Motivation: sharing of documents among systems and databases. 26

Graphs of Semistructured Data Nodes = objects. Labels on arcs (like attribute names). Atomic values at leaf nodes (nodes with no arcs out). Flexibility: no restriction on: Labels out of a node. Number of successors with a given label. 27

bar Example: Data Graph beer root beer Notice a new kind of data. manf manf prize servedat name Bud A.B. name year award name addr M lob 1995 Gold Joe s Maple The bar object for Joe s Bar The beer object for Bud 28

XML XML = Extensible Markup Language. While HTML uses tags for formatting (e.g., italic ), XML uses tags for semantics (e.g., this is an address ). Key idea: create tag sets for a domain (e.g., genomics), and translate all data into properly tagged XML documents. 29

XML Documents Start the document with a declaration, surrounded by <?xml?>. Typical: <?xml version = 1.0 encoding = utf-8?> Balance of document is a root tag surrounding nested tags. 30

Tags Tags, as in HTML, are normally matched pairs, as <FOO> </FOO>. Optional single tag <FOO/>. Tags may be nested arbitrarily. XML tags are case sensitive. 31

Example: an XML Document <?xml version = 1.0 encoding = utf-8?> <BARS> <BAR><NAME>Joe s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> </BARS> A NAME subobject A BEER subobject 32

The Difference Between XML and HTML XML is not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to describe data, with focus on what data is HTML was designed to display data, with focus on how data looks HTML is about displaying information, while XML is about carrying information. 33

Attributes Like HTML, the opening tag in XML can have atttribute = value pairs. Attributes also allow linking among elements (discussed later). 34

Bars, Using Attributes <?xml version = 1.0 encoding = utf-8?> <BARS> <BAR name = Joe s Bar > </BAR> <BAR> </BARS> <BEER name = Bud price = 2.50 /> <BEER name = Miller price = 3.00 /> name and price are attributes Notice Beer elements have only opening tags with attributes. 35

DTD s (Document Type Definitions) A grammatical notation for describing allowed use of tags. Definition form: <!DOCTYPE <root tag> [ <!ELEMENT <name>(<components>)>... more elements... ]> 36

Example: DTD <!DOCTYPE BARS [ <!ELEMENT BARS (BAR*)> <!ELEMENT BAR (NAME, BEER+)> <!ELEMENT NAME (#PCDATA)> <!ELEMENT BEER (NAME, PRICE)> <!ELEMENT PRICE (#PCDATA)> ]> NAME and PRICE are HTML text. A BARS object has zero or more BAR s nested within. A BAR has one NAME and one or more BEER subobjects. A BEER has a NAME and a PRICE. 37

Attributes Opening tags in XML can have attributes. In a DTD, <!ATTLIST E... > declares an attribute for element E, along with its datatype. 38

Example: Attributes <!ELEMENT BEER EMPTY> No closing tag or subelements <!ATTLIST name CDATA #REQUIRED, manf CDATA #IMPLIED> Character string Required = must occur ; Implied = optional Example use: <BEER name= Bud /> 39

Actions Read chapter 1 and chapters 2.1, 2.2 and 2.3 from course book! 40