CCT396, Fall 2011 Database Design and Implementation Yuri - - PowerPoint PPT Presentation

cct396 fall 2011 database design and implementation yuri
SMART_READER_LITE
LIVE PREVIEW

CCT396, Fall 2011 Database Design and Implementation Yuri - - PowerPoint PPT Presentation

CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit


slide-1
SLIDE 1

CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev

University of Toronto

This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from http://everaldo.com/crystal/.

slide-2
SLIDE 2

What is a “Database”?

“an organized collection of data” (digital, managed with software) “DBMS”

slide-3
SLIDE 3

Bob information Alice

slide-4
SLIDE 4

Bob information Alice

slide-5
SLIDE 5

Alice Bob an information system

slide-6
SLIDE 6

Alice Bob storing information + doing things with it

slide-7
SLIDE 7

Alice Bob application software database “persistent storage”

slide-8
SLIDE 8

Alice Bob database “persistent storage”

slide-9
SLIDE 9

What is Data?

Data Information Knowledge

slide-10
SLIDE 10

What is Data?

Values Database Bits Records

slide-11
SLIDE 11

Database Elements

“logical” representation “physical” representation

slide-12
SLIDE 12

Basic Data Types

Numbers 42, 2.7, 7.2×10-19, 879284337621 Text “Strings” “Yoda”, “Chewbacca”, “A long time ago in a galaxy far, far away....”

slide-13
SLIDE 13

More Complex Data

Time “Sept. 7, 2011” (2011-09-07) Binary “Blobs” contents of an image file Geometric a line, a polygon

slide-14
SLIDE 14

Databases Models

slide-15
SLIDE 15

Key-Value

Jedi Master, unknown species smuggler, human Yoda Han Solo

slide-16
SLIDE 16

Hierarchical

characters human wookiee unknown species Padmé Amidala Padmé Amidala Chewbacca Yoda Han Solo Obiwan Kenobi

slide-17
SLIDE 17

Network

human wookiee Chewbacca Yoda Han Solo Obiwan Kenobi Jedi Master

slide-18
SLIDE 18

Relational

A notion of a “relation”

not to be confused with a “relationship”

slide-19
SLIDE 19

A Relation

(“Yoda”, “Jedi Master”)

slide-20
SLIDE 20

A Relation

(“Yoda”, “Jedi Master”, “unknown species”)

slide-21
SLIDE 21

A Relation

(“Yoda”, “Jedi Master”, “unknown species”) (“San Solo”, “smuggler”, “Human”) (“Padmé Amidala”, “queen”, “Human”) (“Jabba”, “crime lord”, “Hutt”) (“Jar Jar Binks”, “senator”, “Gungan”)

slide-22
SLIDE 22

Another Relation

(“Human”, “humanoid”, 1.7) (“Gungan”, “humanoid”, 1.89) (“Hutt”, “gastropod”, 3.5) (“Ewok”, “furry biped”, 0.9)

slide-23
SLIDE 23

And Another

(“humanoid”, 2) (“gastropod”, 0)

slide-24
SLIDE 24

Tabular Form

Human humanoid 1.7 Hutt gastropod 3.5 Jabba Hutt Obiwan Kenobi Human gastropod humanoid 2 persona species_type species

slide-25
SLIDE 25

Tabular Form

Human humanoid 1.7 Hutt gastropod 3.5 Jabba Hutt Obiwan Kenobi Human gastropod humanoid 2 persona species_type species

slide-26
SLIDE 26

Relational Data Modeling

Finding a proper relational representation for data

slide-27
SLIDE 27

RDBMS

MySQL, PostgreSQL, Oracle, Sybase, IBM DB2, Informix, MS SQL Server, MS Access*

slide-28
SLIDE 28

Accessing a Database

slide-29
SLIDE 29

Built-in GUI

slide-30
SLIDE 30

Networked Client

database server database client

slide-31
SLIDE 31

A 3-Tier System

database server application server web client

slide-32
SLIDE 32

A Query Language

commands status, results

slide-33
SLIDE 33

Structured Query Language

(Some people say “Sequel”)

slide-34
SLIDE 34

An SQL Statement

select name, occupation from persona where species=”Wookiee”;

slide-35
SLIDE 35

An SQL Statement

select name, occupation from persona where species="Wookiee";

slide-36
SLIDE 36

Sequel Pro

http://www.sequelpro.com/ (also available in this lab)

slide-37
SLIDE 37

File > New Connection Window

slide-38
SLIDE 38
slide-39
SLIDE 39
slide-40
SLIDE 40
slide-41
SLIDE 41
slide-42
SLIDE 42
slide-43
SLIDE 43
slide-44
SLIDE 44

An SQL Statement

select name, occupation from persona where species="Wookiee";

  • SQL keywords are not case-sensitive (de facto)
  • text strings usually are are
  • names or tables and fields usually are
slide-45
SLIDE 45

An SQL Statement

so: select = SELECT* = seLecT** from = FROM* = From**

* some people prefer this ** ugly, don't do this

but: persona != PERSONA != Persona "Wookiee" != "wookiee"

slide-46
SLIDE 46

Quotes

Text strings must always be quoted Names can be, sometimes must be Quote Types “, ”, and " " must be closed by ", ' by '

slide-47
SLIDE 47

The Semi-Colon

Don’t forget the semi-colon;

slide-48
SLIDE 48

A Terminal App / Bash

OSX: “Terminal” (pre-installed) Linux: “gnome-terminal” (pre-installed) Windows: “git-bash” from Git http://code.google.com/p/msysgit/

(you can use PuTTY if you prefer)

slide-49
SLIDE 49

Local v Remote

Local: Your laptop / desktop Remote: Another computer you are using (via your “local” machine)

Hint: Check the name in the prompt, e.g.: yuri@chai:~$

slide-50
SLIDE 50

SSH

ssh okenobi@yoda.ischool.utoronto.ca

  • your password is your student ID
  • you will need to change your password

You will need to re-enter your original password before entering the new one. That is, the sequence is:

  • riginal, original again, new, new again.
slide-51
SLIDE 51

MySQL

mysql connect to mysql mysql -u username -p connect to mysql as a okenobi, with a password

slide-52
SLIDE 52

MySQL Prompt

mysql> do not confuse with the bash prompt! Hint: type “exit” or ^C to exit.

slide-53
SLIDE 53

Important Keys

image source:http://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Qwerty.svg/1000px-Qwerty.svg.png

command completion quit earlier commands

“Ctrl+C” is usually represented as “^C”

slide-54
SLIDE 54

SQL via SSH

mysql> use starwars; Database changed mysql> select name, occupation from persona where species="Wookiee"; +-----------+------------+ | name | occupation | +-----------+------------+ | Chewbacca | co-pilot | +-----------+------------+ 1 row in set (0.00 sec)

slide-55
SLIDE 55

This Course

http://takhteyev.org/courses/11F/cct395/

slide-56
SLIDE 56

Contact Information

Office hours:

  • Wed, 5-6 pm, Rm. 3008

Email:

  • use the Q&A system if possible
  • if emailing, use UToronto mail
  • put “CCT395” in the subject line
  • expect 2 day turn-around
slide-57
SLIDE 57

The Q&A System

http://cct395.ischool.utoronto.ca/

  • use for all non-private questions
  • feel free to answer too!
slide-58
SLIDE 58

“SQL” “RDD”

slide-59
SLIDE 59

The Course Outline

slide-60
SLIDE 60

Relational Algebra

name

  • ccupation

species Obi-Wan Kenobi Jedi Master Human Yoda Jedi Master NULL Jabba crime lord Hutt Chewbacca co-pilot Wookiee Luke Skywalker Jedi Knight Human Padmé Amidala queen Human persona

slide-61
SLIDE 61

Projection

name

  • ccupation

species Obi-Wan Kenobi Jedi Master Human Yoda Jedi Master NULL Jabba crime lord Hutt Chewbacca co-pilot Wookiee Luke Skywalker Jedi Knight Human Padmé Amidala queen Human persona

slide-62
SLIDE 62

Projection

name species Obi-Wan Kenobi Human Yoda NULL Jabba Hutt Chewbacca Wookiee Luke Skywalker Human Padmé Amidala Human persona

slide-63
SLIDE 63

Selection

name

  • ccupation

species Obi-Wan Kenobi Jedi Master Human Yoda Jedi Master NULL Jabba crime lord Hutt Chewbacca co-pilot Wookiee Luke Skywalker Jedi Knight Human Padmé Amidala queen Human persona (“Restriction” in Harrington)

slide-64
SLIDE 64

Selection

name

  • ccupation

species Obi-Wan Kenobi Jedi Master Human Luke Skywalker Jedi Knight Human Padmé Amidala queen Human persona (“Restriction” in Harrington)

slide-65
SLIDE 65

Columns vs Rows

Projection: choosing columns (fields) by name Selection: choosing rows with a condition

slide-66
SLIDE 66

Basic SELECT

selection followed by projection

select «list of fields» from «source table» where «conditions»; 3. 1. 2.

slide-67
SLIDE 67

Skipping Projection

select * from «table» where «condition»; select * from persona where species="Human"; For instance:

slide-68
SLIDE 68

Skipping Selection

select * from «table»; select * from persona; For instance:

slide-69
SLIDE 69

LIMIT

select ... from ... limit «N»; select name from persona limit 5; For instance:

slide-70
SLIDE 70

Sorting the Results

select ... from ... where ...

  • rder by «expression»;

select name from persona

  • rder by size;

For instance:

slide-71
SLIDE 71

Questions?