creating databases for web applications sql. systems design. er diagrams. data flow diagrams....

32
Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for a library: produce ERD and DFD

Upload: cecilia-cobb

Post on 27-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Creating databases for web applications

SQL. Systems design. ER diagrams. Data flow diagrams.

Storyboards.

Homework: Plan database and applications for a library: produce

ERD and DFD

Page 2: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

SQL Select

• SELECT field1, field2, … FROM table1 WHERE condition AND condition GROUP BY fieldiHAVING condition …ORDER …LIMIT …

• More complex SELECT addsSELECT field1, field2, … FROM table1 JOIN ON condition WHERE condition ….

Page 3: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

System analysis and design

• Tools for planning– communication with clients (specific diagrams

may not always be shown, but used to support discussion)

– communication with builders

• Attempt to focus on function before implementation– logical design versus physical design

non-tech meaning ofterm

Page 4: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Models

• Information model = Entity relationship diagrams– Ask yourself: what is the critical information? What

are the relationships (what fields in one table point to other records?)

• Process model = data flow– What are the (main) processes? Who initiates these

processes? What data stores are used and/or changed?

• Story board– What are the Web pages—the interfaces to the user

(client/player/employee)? What is the flow from one Web page to another?

Page 5: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

ER models

• Done before creating the tables as part of planning and after creating the tables, as documentation

• Logical/analysis level (what is in examples here) just defines fields and relationships. Physical/Design/Implementation level: data types and also estimates on number of records.

Page 6: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Entity-relationship

• Entity = the things (products, people, places, business concepts)– attributes = fields = properties

• Relationships = connections between things, as represented by a field in one table (attribute of an entity) pointing to an entity.

Page 7: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Primary keys and foreign keys

• A field (attribute) that uniquely defines a record in a table can be its primary key.– sometimes generated automatically by dbms

• In another table, the way to refer to this record would be by using the primary key value. This is called a foreign key in that other table.

Page 8: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Entity Relationship diagrams

• Blocks represent the records in the table. Typically, they list all the fields.

• Lines between the blocks represent relationships. The marks on the lines indicate the numbers, e.g., one to many, one to one. They also indicate what a minimum would be. – 0 means that an entity in one table may not

be referenced in the other at all.

Page 9: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Example: trivia quiz

Tables are

• Questions

• Players

• History (that is, a question was asked [of] a player on a specific date, with outcome correct or not correct– Each item in History relates to a specific

player and a specific question

Page 10: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Trivia quiz

– http://socialsoftware.purchase.edu/jeanine.meyer/quiz/choosecategory.php

– http://socialsoftware.purchase.edu/jeanine.meyer/quiz/showscores.php

– http://socialsoftware.purchase.edu/jeanine.meyer/quiz/inputquestions.php

• No registration.

• Rule on asking questions.

Page 11: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Question databank table

question_id

Question

Answer (answer pattern)

Value

Category

Players table

player_id

Player name

Score

lastplayed date

history table

question_id

player_id

whenplayed

correct0

0

Page 12: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Course pre-req example

• In this design, each course has at most one pre-requisite course.

Page 13: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Course

course title

Division

Pre-requisite

0

0

Page 14: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Course pre-reqs, more complete

• Each course can have no, 1, or any number of pre-requisites.

• TWO TABLES!– Courses– Statements of pre-reqs

Page 15: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Course

Course title

Division

Statement of pre-requisites

Course to be taken

pre-required course (prior course)

Each statement of pre-requisites refers to exactly one course and exactly one 'pre-req'. A course can be in either position, zero, oneor several times. Creating Web Documents is a pre-req for

Creating Dynamic Web Docs & Creating DBs for WebSome courses may have pre-requisites of more than one course.

0

0 0

Page 16: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Data design

• Sometimes done by taking the artifacts (forms, reports, screens) and writing down all those fields into first draft of records– These artifacts can be from the current system or the proposed

materials for a new system• Apply a technique called normalization to get well-

defined entities and relationships.– First step is making sure each record has fixed number of fields.

• For example, not indefinite number of pre-reqs– Subsequent steps ensure that data is not repeated, so

information only needs to be updated in one place• Make customer data be in a customer file NOT in each transaction

file– EXTRA CREDIT opportunity for posting

Page 17: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Process diagram

Focus on• Blocks

– processes– agents (this could be people in specific roles or 'the

system' triggered by events, including a time condition)– data stores: more general term than databases. Here we

can use it to refer to tables that are in a database or file or built into script

• Connections– Agent engaged with process– Process using data store

Page 18: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Player

Editor

Play game

Edit questions

Questions table

Player table

Data flow diagram (process diagram) for quiz show

History table

Page 19: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Story board

• more implementation based than the others

• Therefore, part of system build, not system design, or, perhaps, System Physical Design not Logical Design

• focus on the scripts and how the scripts call each other

Page 20: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Create quiz tables (php only)

Input Questions (handles form input)

Choose category

Ask question

Check answer

Clear tables

Include/Required file: opendbq

Show scores

Page 21: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Entities for store

Initial design

• catalog of products

• orders– one or more ordered items

• customer list

Enhanced design

• Need 1 more table: call it ordered items

Page 22: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Product catalogProduct idProduct namePictureCost

Customer listCustomer IDfirst namelast nameBilling informationE-mailPassword

Order listOrder IDCustomer IDDateStatusTotal

Ordered itemsOrder IDProductQuantity

0

ER diagram for on-line store

0

Page 23: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Customer

Billing system (timed event)

Browse/Order

Billing

Catalog

Customer list

Current ordersOrdered items

Shipping clerk

Shipping

Data flow (process) diagram for on-line store.

Note that this is the information/data flow, not the flow of goods. The shipping operation produces a physical product: the collection of ordered items, packed and set off for delivery.

Page 24: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Storyboard of partial implementation: ordering

Create tables (php only)

Include/require: opendbo

Input products

Order product

makeorder

Shopping cart

Submit order

Delete current customer cookie

Include/require: displaycartfunction

Page 25: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Song with features example

• Bare bones

• Song table and Feature table plus

• A song can have 0 or more features

• Intention is to provide way of detecting songs similar to a given song– Complex SQL statement!

Page 26: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Song features

song

id

Name

Description

Year

featureidnamedescription

feature of song

fisid

fid

fid

0

0

Page 27: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Song with features storyboard

createtables.php

addsong.html addsong.php

addfeature.html addfeature.php

addfeaturestosong1.php addfeaturestosong2.php

deletefeaturesinsongs.php

findothers1.php findothers2.php

listallfeaturesinsongs.php

opendbe.php (included inall php files)

Page 28: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Songs with features DFD

Add songs

Identify songs

Add features to song

Admin FinderAdd feature

Song info

Edit info

Page 29: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Agents

• Of course in these toy applications such as the songs with features, there is just one agent (me!) but

• Important to plan what are roles of system builders versus system users– End users (maybe customers, clients)– System maintainers

• Some social networking song sites do allow users to add songs, specify features, add features, etc.

Page 30: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Opportunity for improvement

• Functions mentioned but not implemented (in orange)

• Navigation could be better– specifically, going back or 'coming out of' steps.

Where to go

• Teams will review and enhance these projects and present whole thing to the class.

Page 31: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Classwork / Homework

• Design ER and DFD for a library.• YOUR job is to define entities, relationships,

agents, data stores, processes.• Logical design, not physical design• Note: a data store could be manual. Don't be

concerned with that.

This is a paper-and-pencil activity, though you can using drawing tools in Word or Powerpoint or ??.

Page 32: Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for

Homework• Catch up programming. Post links to

Information, etc. forum:– Simple parallel arrays application

• Like my state capital quiz

– One table database application• Like my books application

• Catch up unique sources assignments. Post on Sources you find forum: – php, MySQL (or SQL), regular expressions, ER or

DFD or Select statement