1 CS351 Introduction to Database systems

Slides:



Advertisements
Similar presentations
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Model Fall 2014.
Advertisements

Chapter 7 Notes on Foreign Keys Local and Global Constraints Triggers.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
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.
1 More SQL Defining a Database Schema Views. 2 Defining a Database Schema uA database schema comprises declarations for the relations (“tables”) of the.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Winter 2002Arthur Keller – CS 1809–1 Schedule Today: Jan. 31 (TH) u Constraints. u Read Sections , Project Part 3 due. Feb. 5 (T) u Triggers,
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
Fall 2001Arthur Keller – CS 1809–1 Schedule Today Oct. 23 (T) Constraints. u Read Sections Assignment 4 due. Project Part 3 due Oct. 24 (W). Oct.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #3.
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.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #2.
Database Systems Lecture 5 Natasha Alechina
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
CS462: Introduction to Database Systems. ©Silberschatz, Korth and Sudarshan1.2Database System Concepts Course Information Instructor  Kyoung-Don (KD)
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
CSC2012 Database Technology & CSC2513 Database Systems.
SCUHolliday - coen 1789–1 Schedule Today: u Constraints, assertions, triggers u Read Sections , 7.4. Next u Triggers, PL/SQL, embedded SQL, JDBC.
CST203-2 Database Management Systems Lecture 2. One Tier Architecture Eg: In this scenario, a workgroup database is stored in a shared location on a single.
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.
Databases 1 First lecture. Informations Lecture: Monday 12:15-13:45 (3.716) Practice: Thursday 10:15-11:45 (2-519) Website of the course:
Databases : SQL-Introduction 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
1 CE223 Database Systems Introduction DBMS Overview, Relational Model, Schemas, SQL Semistructured Model, XML.
1 Lecture 1 Introduction Based on
Introduction to Database Management Systems. Information Instructor: Csilla Farkas Office: Swearingen 3A43 Office Hours: Monday, Wednesday 4:15 pm – 5:30.
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
Databases 1 Fourth lecture. Rest of SQL Defining a Database Schema Views Foreign Keys Local and Global Constraints Triggers 2.
Winter 2006Keller, Ullman, Cushing9–1 Constraints Commercial relational systems allow much more “fine-tuning” of constraints than do the modeling languages.
1 CS1368 Introduction* Relational Model, Schemas, SQL Semistructured Model, XML * The slides in this lecture are adapted from slides used in Standford's.
RELATIONAL DATA MODEL 1. 2 What is a Data Model? 1.Mathematical representation of data. wExamples: relational model = tables; semistructured model = trees/graphs.
Introduction to Database Management Systems. Information Instructor: Csilla Farkas Office: Swearingen 3A43 Office Hours: M,T,W,Th,F 2:30 pm – 3:30 pm,
1 Chapter 1 Introduction. 2 Introduction n Definition A database management system (DBMS) is a general-purpose software system that facilitates the process.
1 Introduction Relational Model, Schemas, SQL Semistructured Model, XML The slides were made by Jeffrey D. Ullman for the Introduction to Databases course.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
Introduction to Database Management Systems. Information Instructor: Csilla Farkas Office: Swearingen 3A43 Office Hours: Monday, Wednesday 2:30 pm – 3:30.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
1 Database Systems Defining Database Schema Views.
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.
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.
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
1 Introduction to SQL Database Systems. 2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
Mr.Prasad Sawant, MIT Pune India Introduction to DBMS.
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
ASET 1 Amity School of Engineering & Technology B. Tech. (CSE/IT), III Semester Database Management Systems Jitendra Rajpurohit.
Chapter 1: Introduction. 1.2 Database Management System (DBMS) DBMS contains information about a particular enterprise Collection of interrelated data.
SCUHolliday - coen 1789–1 Schedule Today: u Constraints, assertions, triggers u Read Sections , 7.4. Next u Embedded SQL, JDBC. u Read Sections.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
©Silberschatz, Korth and Sudarshan 1.1 Database System Concepts قواعد البيانات Data Base قواعد البيانات CCS 402 Mr. Nedal hayajneh E- mail
1 Introduction to Database Systems, CS420 SQL Constraints.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Database Design and Programming Jan Baumbach Adopted from previous slides of Peter Schneider-Kamp.
1. 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational.
CMPT 354 Database Systems I
CPSC-310 Database Systems
Relational Data Model Lu Chaojun, SJTU.
CPSC-310 Database Systems
What is sql?.
Introduction to Database Systems, CS420
Introduction to Database Systems, CS420
Database Design and Programming
CPSC-608 Database Systems
CS 440 Database Management Systems
Database Models Relational Model
SQL OVERVIEW DEFINING A SCHEMA
CPSC-608 Database Systems
CMSC-461 Database Management Systems
CE223 Database Systems Introduction
Presentation transcript:

1 CS351 Introduction to Database systems

2 About me Quan Wang – developer at Oracle Corp. JDBC Web Services Cloud

3 Content  Introduction – Why databases?  Data Model

4 Why 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 Why databases?  You may not notice it, but databases are behind almost everything you do on the Web.  Google searches.  Queries at Amazon, eBay, etc.

6 Why databases?  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.

7 Why databases?  Changing landscape  System R: Oracle, MySQL, IBM, MS  NoSQL: MangoDB  NewSQL: VoltDB  Cloud: Amazon RDS, Google Bigquery  Bigdata: Hadoop, MapR

8 Why databases?  Job perspectives – Startups – Massive industry

9 Content  Introduction – Why database? – What to cover?  Data Model

10 What to cover?  Database – a set of inter-related data pertaining to some organization – airline, university, store  Database Management System (DBMS) – one or more databases – algorithms accessing the databases

11

12 What to cover?  Database Theory – relational model and algebra – norm forms  Design of databases. – normalization – E/R, UML

13 What to cover?  Database programming – SQL, stored procedures.  Integration? – ODBC, JDBC – O-R Mapping

14 What not covered?  Not covered – DB tuning – DB administration(DBA) – DB implementation – Programming languages May need to learn languages and the DB related aspects

15 Content  Introduction – Why database? – What to cover? – Logistics  Data Model

16 Logistics Office hour – Tuesday & Thursday – 1 pm to 2pm – 201L

17 Logistics No TA No detailed comments on assignments Distribute answer keys when appropriate Check discrepancies Raise issues

18 Logistics Course page: – ang ang – weekly schedule, assignments Submission page – – Use drop box for assignments and project submission

19 Logistics Assignments 30% Team project 20% Midterms 25% Final 25%

20 Logistics Team project – mini-ebay – Max 3 people each team – Single grade for each team Assignments and project – Late submission 10% penalty

21 Logistics Databases – MySQL – SQLite /usr/bin/sqlite3

22 Logistics Exams – Lectures, textbook, and assigned readings – Only areas covered in the lectures – Not curved

23 Content  Introduction Why database? What to cover? Logistics  Data Model – Why not flat files?

24 Why not flat files? data savings.dat NAME,ADDR,BALANCE,OPENED,INTEREST David, 123 NW Flanders St, , 08/20/2010, 0.005! Lisa, 432 NE Alberta St, , 09/20/2001, operations – check balance – deposit or withdraw – change address

25 Why not flat files? data David, 123 NW Flanders St, , 08/20/2010, 0.005! Lisa, 432 NE Alberta St, , 09/20/2001, problems – code coupled with data format changing delimiter would require code change

26 Why not flat files? data Savings.data: David, 123 NW Flanders St, , 08/20/2010, 0.005! Lisa, 432 NE Alberta St, , 09/20/2001, Checkings.data: David, 789 NE Sany Blvd, 1500, 08/20/1998, 0.001! Lisa, 432 NE Alberta St, 3500, 09/20/1990, 0 problems – redundancy leads to inconsistency

27 Why not flat files? data David, 123 NW Flanders St, , 08/20/2010, Lisa, 432 NE Alberta St, , 09/20/2001, problems – concurrency withdraw calls for file lock –withdraw $100 from the same account at the same time, synchronized – withdraw $100 from different accounts at the same time, synchronized unnecessarily

28 Why not flat files? data David, 123 NW Flanders St, , 08/20/2010, Lisa, 432 NE Alberta St, , 09/20/2001, problems – user interface file based algorithms

29 Why not flat files? summary – code coupled with data – redundancy leading to inconsistency – low concurrency – unfriendly user interface

30 Why not flat files? database as abstraction data model hides data format SQL hides algorithms runtime handles concurrency

31 Content  Introduction  Data Model – why not flat files? – relational data model relations schema keys

32 What is a Data Model? 1.Underlying structure of a database. 2.Mathematical representation of data.  Examples: relational model = tables; semistructured model = trees/graphs; key-value model=key value pairs. 3.Operations on data. 4.Constraints.

33 A Relation is a Table name manf WinterbrewPete’s Bud LiteAnheuser-Busch Beers Attributes (column headers) Tuples (rows) Relation name

34 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.

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

36 Example Beers(name, manf) Bars(name, addr) 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.

37 Example Sells(bar,beer,price )Bars(name,addr ) Joe’sBud2.50Joe’sMaple St. Joe’sMiller2.75Sue’sRiver Rd. Sue’sBud2.50 Sue’sCoors3.00

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

39 Creating (Declaring) a Relation  Simplest form is: CREATE TABLE ( );  To delete a relation: DROP TABLE ;

40 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.

41 Example: Create Table CREATE TABLE Sells ( barCHAR(20), beerVARCHAR(20), priceREAL );

42 SQL Values  Integers and reals are represented as you would expect.  Strings are too, except they require single quotes.  Two single quotes = real quote, e.g., ’Joe’’s Bar’.  Any value can be NULL.

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

44 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.

45 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.

46 Declaring Single-Attribute Keys  Place PRIMARY KEY or UNIQUE after the type in the declaration of the attribute.  Example: CREATE TABLE Beers ( nameCHAR(20) UNIQUE, manfCHAR(20) );

47 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.

48 Example: Multiattribute Key  The bar and beer together are the key for Sells: CREATE TABLE Sells ( barCHAR(20), beerVARCHAR(20), priceREAL, PRIMARY KEY (bar, beer) );

49 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.

50 Content  Introduction  Data Model – why not flat files? – relational data model relations schema keys – why relations?

51 Why relations? data savings.dat NAME,ADDR,BALANCE,OPENED,INTEREST David, 123 NW Flanders St, , 08/20/2010, 0.005! Lisa, 432 NE Alberta St, , 09/20/2001, 0.006

52 Terminalogy DDL: Data Definition Language CREATE TABLE DML: Data Manipulation Language INSERT SQL: Structured Query Language SELECT...FROM...WHERE

53 Why relations? schema Savings( name CHAR(50), addr CHAR(50), balance REAL, opened DATE, interest REAL);

54 Why relations? relation operations – check balance – deposit or withdraw – change address nameaddrbalanceopenedinterest David123 NW Flander St Lisa432 Alberta St

55 Why relations? relation advantage – code coupled with data format? nameaddrbalanceopenedinterest David123 NW Flander St Lisa432 Alberta St nameaddrbalanceopenedinterest David123 NW Flander St Lisa432 Alberta St

56 Why relations? relation advantage – concurrency simultaneous withdraw calls nameaddrbalanceopenedinterest David123 NW Flander St Lisa432 Alberta St

57 Why relations? relations advantage – redundancy? Savings(name, addr, balance, opened, interest) Checkings(name, addr, balance, opened, interest)

58 Why relations? relations advantage – redundancy? nameaddrbalanceopenedinterest David123 NW Flander St Lisa432 Alberta St nameaddrbalanceopenedinterest David Sandy Blvd Lisa432 Alberta St Savings Checkings

59 Why relations? relations advantage – redundancy? Customers(cust_id, name, addr) Savings(cust_id, balance, opened, interest) Checkings(cust_id, balance, opened, interest)

60 Why relations? relations advantage – redundancy? cust_id nameaddr c1 David123 NW Flander St c2 Lisa432 Alberta St cust_idbalanceopenedinterest c c cust_idbalanceopenedinterest c c Customers Savings Checkings

61 Why relations? relation advantage – user interface natural language like support desirable nameaddrbalanceopenedinterest David123 NW Flander St Lisa432 Alberta St

62 Why relations? relation advantage – user interface SELECT name, addr FROM savings WHERE balance>2000 NAMEADDRBALANCEOPENEDINTEREST David123 NW Flander St Lisa432 Alberta St

63 Why relations? relation advantage – user interface SELECT name, addr, balance FROM savings ORDER BY balance NAMEADDRBALANCEOPENEDINTEREST David123 NW Flander St Lisa432 Alberta St

64 Content  Introduction  Data Model – why not flat files? – relational data model – why relations?

65 Content  Introduction  Data Model – why not flat files? – relational data model – why relations? – semi-structured data models XML and JSON

66 Parsing Techniques Dick Grune Ceriel J.H. Jacobs 2007 Springer XML

67 JSON { "Book": { "Title": "Parsing Techniques", "Authors": [ "Dick Grune", "Ceriel J.H. Jacobs" ], "Date": "2007", "Publisher": "Springer" } }

68 XML and JSON, side-by-side Parsing Techniques Dick Grune Ceriel J.H. Jacobs 2007 Springer { "Book": { "Title": "Parsing Techniques", "Authors": [ "Dick Grune", "Ceriel J.H. Jacobs" ], "Date": "2007", "Publisher": "Springer" } }

69 XML Schema

70 JSON Schema { "$schema": " "type": "object", "properties": { "Book": { "type": "object", "properties": { "Title": {"type": "string"}, "Authors": {"type": "array", "minItems": 1, "maxItems": 5, "items": { "type": "string" }}, "Date": {"type": "string", "pattern": "^[0-9]{4}$"}, "Publisher": {"type": "string", "enum": ["Springer", "MIT Press", "Harvard Press"]} }, "required": ["Title", "Authors", "Date"], "additionalProperties": false } }, "required": ["Book"], "additionalProperties": false }

71 String type { "$schema": " "type": "object", "properties": { "Book": { "type": "object", "properties": { "Title": {"type": "string"}, "Authors": {"type": "array", "minItems": 1, "maxItems": 5, "items": { "type": "string" }}, "Date": {"type": "string", "pattern": "^[0-9]{4}$"}, "Publisher": {"type": "string", "enum": ["Springer", "MIT Press", "Harvard Press"]} }, "required": ["Title", "Authors", "Date"], "additionalProperties": false } }, "required": ["Book"], "additionalProperties": false }

72 List type { "$schema": " "type": "object", "properties": { "Book": { "type": "object", "properties": { "Title": {"type": "string"}, "Authors": {"type": "array", "minItems": 1, "maxItems": 5, "items": { "type": "string" }}, "Date": {"type": "string", "pattern": "^[0-9]{4}$"}, "Publisher": {"type": "string", "enum": ["Springer", "MIT Press", "Harvard Press"]} }, "required": ["Title", "Authors", "Date"], "additionalProperties": false } }, "required": ["Book"], "additionalProperties": false }

73 Year type { "$schema": " "type": "object", "properties": { "Book": { "type": "object", "properties": { "Title": {"type": "string"}, "Authors": {"type": "array", "minItems": 1, "maxItems": 5, "items": { "type": "string" }}, "Date": {"type": "string", "pattern": "^[0-9]{4}$"}, "Publisher": {"type": "string", "enum": ["Springer", "MIT Press", "Harvard Press"]} }, "required": ["Title", "Authors", "Date"], "additionalProperties": false } }, "required": ["Book"], "additionalProperties": false }

74 Enumeration type { "$schema": " "type": "object", "properties": { "Book": { "type": "object", "properties": { "Title": {"type": "string"}, "Authors": {"type": "array", "minItems": 1, "maxItems": 5, "items": { "type": "string" }}, "Date": {"type": "string", "pattern": "^[0-9]{4}$"}, "Publisher": {"type": "string", "enum": ["Springer", "MIT Press", "Harvard Press"]} }, "required": ["Title", "Authors", "Date"], "additionalProperties": false } }, "required": ["Book"], "additionalProperties": false }

75 Semi-Structured Data Models  XML Adoption – Web Services (SOAP) – XML DB  JSON Adoption – Web Services (REST) – MongoDB

76 Content  Introduction  Data Model – why not flat files? – relational data model – why relations? – semi-structured data models – history

77 History Hierarchical (IMS): late 1960’s and 1970’s Network (CODASYL): 1970’s Relational: 1970’s and early 1980’s Entity-Relationship: 1970’s Object-oriented: late 1980’s and early 1990’s Object-relational: late 1980’s and early 1990’s Semi-structured (XML): late 1990’s to the present