SQL, Data Storage Technologies, and Web-Data Integration Week 2.

Slides:



Advertisements
Similar presentations
Chapter 10: Designing Databases
Advertisements

BUSINESS DRIVEN TECHNOLOGY Plug-In T4 Designing Database Applications.
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 5/1 Copyright © 2004 Please……. No Food Or Drink in the class.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
IT420: Database Management and Organization
A Practical Introduction to Transactional Database Modeling and Design Mike Burr.
Logical Data Modeling Review Lecture for University of Agder, Grimstad DAT202 Databaser (5.5.11) Judith Molka-Danielsen
Relational Databases Relational Model Primary Keys Relation or Relationship Foreign Keys Relationships between entities Integrity Constraints Power of.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 8.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
Fundamentals, Design, and Implementation, 9/e Chapter 5 Database Design.
Data Management Design
3-1 Chapter 3 Data and Knowledge Management
Data Modelling. EAR model This modelling language allows a very small vocabulary: Just as English has nouns, verbs, adjectives, pronouns.., EAR models.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
CSE 1561 Designing Relational Databases Stephen Scott.
Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 1 Data Models: Degrees of Data Abstraction l Modified ANSI/SPARC Framework.
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.
SQL, Data Storage Technologies, and Web-Data Integration Week 1.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Chapter 14 & 15 Conceptual & Logical Database Design Methodology
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
IST Databases and DBMSs Todd S. Bacastow January 2005.
Daniel AdinugrohoDatabase Programming 1 DATABASE PROGRAMMING Lecture on 29 – 04 – 2005.
ระบบฐานข้อมูลขั้นสูง (Advanced Database Systems) Lecturer AJ. Suwan Janin Phone:
Module Title? DBMS E-R Model to Relational Model.
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall 9.1.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Relational DB Components
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
Concepts and Terminology Introduction to Database.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Fundamentals of Relational Database Operations
McGraw-Hill/Irwin © 2008 The McGraw-Hill Companies, All Rights Reserved Plug-In T5: Designing Database Applications Business Driven Technology.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
M1G Introduction to Database Development 2. Creating a Database.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Relational Database. Database Management System (DBMS)
CIS 210 Systems Analysis and Development Week 6 Part II Designing Databases,
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Description and exemplification of entity-relationship modelling.
In this session, you will learn to: Map an ER diagram to a table Objectives.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
Advanced Web 2012 Lecture 3 Sean Costain What is a Database? Sean Costain 2012 A database is a structured way of dealing with structured information.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Object Oriented Database By Ashish Kaul References from Professor Lee’s presentations and the Web.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
Chapter 10 Designing Databases. Objectives:  Define key database design terms.  Explain the role of database design in the IS development process. 
Data modeling Process. Copyright © CIST 2 Definition What is data modeling? –Identify the real world data that must be stored on the database –Design.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Logical Database Design and the Relational Model.
Lecture 4: Logical Database Design and the Relational Model 1.
Creating E/R Diagrams with SQL Server Management Studio, Writing SQL Queries D0ncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer.
Database Planning Database Design Normalization.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Basics Review Reviewing what we’ve learned so far…….
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 Entity Relationship Approach u Top-down approach to data modeling u Uses diagrams u Normalization - confirms technical soundness u Entity Relationship.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
Logical Database Design and the Rational Model
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
CSIS 115 Database Design and Applications for Business
Translation of ER-diagram into Relational Schema
© 2011 Pearson Education, Inc. Publishing as Prentice Hall
SQL, Data Storage Technologies, and Web-Data Integration
Presentation transcript:

SQL, Data Storage Technologies, and Web-Data Integration Week 2

Today’s Agenda Review First Week Data Modeling, ER Diagrams Normalization techniques –2 nd Normal Form –3 rd Normal Form Physical Data Model

First Normal Form First Normal Form (1NF) occurs when all attributes are single valued. –No repeating or attributes with multiple values Examples: –A Movie entity with attributes actor1, actor2, actor3. –A Sundae entity with a “toppings” attributes

In Class Exercise Create an Data Model in 1 st Normal Form for the following applications: 1.Recipes 2.Dating Service 3.Bookstore 4.Photo Sharing 5.Movie Collection

1 st NF Data Model / ER Diagram

ER Diagram Terminology NULL: The database term for a value that does not exist. –What attributes in our data model could be NULL? Unique Identifiers (IDs) –Every entity needs a Unique Identifier –It must be unique across all instances of an entity –It must not be NULL –Its value must never change.

Unique Identifiers How do we pick IDs? –From attributes What are the IDs in our data model? –Auto-generated IDs Very common Security Issues

Relationships An association between two entities Indicates the degree of the relationship –one and only one (also zero or one) –one or many (also zero or many) Examples: –A Donor gives one or many Donations –A Donation is given by one and only one Donor What are the relationships in our model?

Relationships Three degrees make three types of relationships One to one –rare One to many –very common Many to many –will need special handling

ER Diagrams Entities are rectangles Attributes are ellipses Unique IDs are underlined Relationships are lines between entities –Straight line for one and only one –“Crow’s foot” for one or many –Can use bars and circles to represent one or zero

Data Model Relationships

Junction Entities Many to many relationships can be hard to represent in a RDBMS They are replaced with junction entities –Take the many-to-many relationship –Replace it with an entity –Create two new one-to-many relationships to the new entity Which side should the “many” be?

Data Model with Junction Entity

New Example Data Donor IDNameAddressPhone 1Fred Smith 123 Bedrock com 2Beth Kirsh 104 Ballard Erin Lovett 1580 Stone Ln com Donation IDAmountDateP Name /02/04Martha /11/04Jim /07/04Jim /02/04Jim Division IDName 1Marketing 2Child-care 3Trips DonationToDivision IDPercentage 1100% 250% 3

ER Diagram Terminology Non-identifying attribute: An attribute that is not the Unique ID and is dependent on the Unique ID. Repeating entries are often a sign of an non-dependent attribute Examples: –Is Donor Name a non-identifying attribute? –Is Processor name?

2 nd Normal Form (2NF) Model has to be in 1NF All attributes must be non-identifying attributes. To make 2NF, we have two options –Create a new entity for the attribute –Move the attribute to the entity where it really belongs

2 nd Normal Form

Don’t simply look for repeating entries to determine 2NF Example: Is percentage already in 2NF? Many entries have 100% for their value –Yes –The value is dependent on the DonationToDivisionID –Percentage also doesn’t make sense as an Entity: it has no attributes other than itself, and 75% isn’t a “thing”.

3 rd Normal Form Must already be in 2 nd normal form Non-identifying attributes cannot be dependent on each other. Examples: –Employee(eid, name, position, salary) –Address(street, city, state, state abbr.) Move the dependent attributes into a new Entity

3 rd Normal Form

In Class Exercise Update your Data Models to 3 rd Normal Form for the following applications: 1.Recipes 2.Dating Service 3.Bookstore 4.Photo Sharing 5.Movie Collection

Physical Database Design ER Diagram completed – review design carefully Time to convert our conceptual ER diagram into a real database system.

Physical Database Design Step 1 –Convert all entities into tables A database is typically made up of many tables A table is made up of columns and rows Each row in a table represents one instance of the entity

Physical Database Design Step 2 –Attributes become columns in the tables Important to pick the appropriate data type for the columns More on data types later

Physical Database Design Step 3 –Unique IDs become primary keys Remember, they cannot be NULL, and no duplicates are allowed Primary key is the just the database name for an entity’s unique ID – Primary keys are automatically indexed by the database (more on this later)

Physical Database Design Step 4 –Relationships become foreign keys in one table of the relationship. A foreign key is a unique ID of another table. –This creates a reference to a unique row in another table This simply means we have a column in one table that contains the unique ID of the other table.

Physical Database Design Step 4 Continued Which table does the foreign key belong in for a one-to-many relationship? –Store the unique ID from the "one" side of the relationship in the table representing the "many" side of the relationship

Physical Database Design Donor DonorIDName addressPhone number Donation DonationIDDateAmountDonorIDProcessorID Processor ProcessorIDname DonationToDivision DonationToDivisionIDPercentageDonationIDDivisionID Division DivisionIDname

Primary Keys & Unique IDs edu/dl/webulearningobjects/media _fit/ids.html

Data Types Each database has its own data types –Most share a common core of data types, including integers, character strings, and dates. MySQL has 36 different data types

Data Types Numeric Types –store numeric data such as integers and floating point numbers –Modifiers: UNSIGNED: 0 to 255 instead of -128 to 127 AUTO_INCREMENT: integers only, one per table

Data Types Numeric Types Cont.

Data Types String Types –store textual data. –Modifiers: BINARY: allows case-sensitive searching

Data Types String Types Cont.

Data Types Date types –store dates and times

Data Types Complex data types –Enumerations (ENUM) list of predefined strings, value must be one of them. –Sets (SET) list of predefined strings, value can be any combination of them.

Current Physical Database Design Donor DonorIDName addressPhone number Donation DonationIDDateAmountDonorIDProcessorID Processor ProcessorIDname DonationToDivision DonationToDivisionIDPercentageDonationIDDivisionID Division DivisionIDname

New Physical Database Design Donor table: includes types!

Physical Database Design Choosing Column Options –Column options help enforce data integrity –Can make the programmer’s job easier –Which makes the DBA’s job easier Column Options –NULLs allowed, default values, auto incrementing values, and keys

Column Options NOT NULL –By default, columns can contain a NULL instead of a value; this overrides that behavior –Requires that some value always exists in that column for any given row of data. –Will cause a database error if the programmer tries to add a NULL to that column. –What should be NOT NULL in our donation ER diagram?

Column Options DEFAULT value –If a user doesn’t supply a value for a column, you can specify a default value –Example: For a local organization, State and Country might default to WA, USA –Should there be any DEFAULT columns in our donation database?

Column Options AUTO_INCREMENT –Provides a default value to an INTEGER column –The value will automatically be incremented for each insert –Only one column per table can have this option. –Great option for an internal (meaning not shown to a external user) primary key

Column Options PRIMARY KEY –Creates an index on the column –Forces each column entry to be unique from all other column entries –Automatically is NOT NULL UNIQUE –Just like PRIMARY KEY, without the special name.

Physical Database Design Now includes column options!

Relational Database Schema We now have our database schema Whereas our E/R Diagram was very abstract, we now have a very concrete, relational design Requirements / Ideas Database Schema E/R DiagramRDBMS

In Class Exercise Turn your Data Models into Database Schemas: 1.Recipes 2.Dating Service 3.Bookstore 4.Photo Sharing 5.Movie Collection