Exam 1 Review: ERDs, Schemas, SQL Out Describe Elements of an ERD Create Schema from ERD Notes: Associative Entities.

Slides:



Advertisements
Similar presentations
© Abdou Illia MIS Spring 2014
Advertisements

Entity-Relationship Model and Diagrams (continued)
WELL-DESIGNED DATABASES Process faster Easy to develop and maintain Easy to read and write code.
CS34311 The Entity- Relationship Model. CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design Conceptual.
Entity PrimaryKey Attribute relationship Cardinality: zero to many Cardinality: one and only one Cardinality: one to many Explanation Entity Relationship.
MIS2502: Data Analytics Relational Data Modeling
Computer Science 101 Web Access to Databases SQL – Extended Form.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
Review Session What is data, what is information, and give a real world example to differentiate these two concepts.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
MIS2502: Data Analytics Coverting ERD into a DB Schema David Schuff
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
What we’ve learnt Doc 5.69 Doc 5.70 Section 1-3. A simple database Related objects Tables hold the data Forms, reports, queries to access the data.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Getting to Know SQL. © Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM.
2141-W2013 Mid-term Prep. Next week Monday, Feb 18 – Midterm Covers everything before normalization Wednesday, Feb 20 – Ass 3 (normalization) due – Wrap.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
1 The Information School of the University of Washington Dec 1fit advdatabases © 2006 University of Washington Advanced Database Concepts INFO/CSE.
An Entity Relationship (ER) Diagram is a graphic that shows the interrelationship between entities in a database.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
COMP231 Tutorial 1 ER Model and ER to Relational Schema.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 2 Introduction to a First Course in Database Systems.
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
Relational Theory and Design
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
IST 318 – DB Administration Data Retrieval Using SELECT statements.
5-1 McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
MIS2502: Data Analytics Relational Data Modeling
Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
SQL SELECT Getting Data from the Database. Basic Format SELECT, FROM WHERE (=, >, LIKE, IN) ORDER BY ; SELECT LastName, FirstName, Phone, City FROM Customer.
RELATIONAL DATA MODELING MIS2502 Data Analytics. What is a model? Representation of something in the real world.
Prepare an ERD for the following scenario Renting a movie at Blockbuster: Each movie is described by an ID, name, genre (horror, comedy, drama, romantic,
COMP 430 Intro. to Database Systems Multi-table SQL Slides use ideas from Chris Ré and Chris Jermaine. Get clickers today!
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
MIS2502: Data Analytics Relational Data Modeling David Schuff
Howard Paul. Sequential Access Index Files and Data File Random Access.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
Data Modeling AND ER MODELS.
Hoi Le. Why database? Spreadsheet is not good to: Store very large information Efficiently update data Use in multi-user mode Hoi Le2.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
MIS2502: Data Analytics Relational Data Modeling
 2012 Pearson Education, Inc. All rights reserved.
Tables and Their Characteristics
Chapter 7 Entity-Relationship Model
MIS5101: Business Intelligence Relational Data Modeling
Entity-Relationship Model and Diagrams (continued)
Order Database – ER Diagram
ERD’s REVIEW DBS201.
The Entity-Relationship Model
MIS2502: Data Analytics Relational Data Modeling
MIS2502: Review for Exam 1 JaeHwuen Jung
MIS2502: Data Analytics Converting ERDs to Schemas
Access: SQL Participation Project
MIS2502: Data Analytics Relational Data Modeling
MIS2502: Review for Exam 1 Aaron Zhi Cheng
Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the.
Chengyu Sun California State University, Los Angeles
MIS2502: Data Analytics Relational Data Modeling
MIS2502: Data Analytics Relational Data Modeling 2
MIS2502: Data Analytics Relational Data Modeling 3
Presentation transcript:

Exam 1 Review: ERDs, Schemas, SQL Out Describe Elements of an ERD Create Schema from ERD Notes: Associative Entities

Section Course Has CRN Seats CourseID Title Describe Elements of this ERD Convert it into a Schema Location 1 table many table

ER Diagram Elements Entities? – Rectangles: Section, Course Attributes? – Ovals: CRN, Seats, Location, CourseID, Title Relationships? – Diamonds: Course HAS Section Cardinality of Relationship? – 1 course has at least one, at most many sections – 1 section has at least one, at most one course

Create the Schema: Rules Primary key field of “1” table put into “many” table as foreign key field 1:many relationships Relationship Becomes its Own Table Has many:1 relationships with original tables many:many relationships Primary key field of one table put into other table as foreign key field 1:1 relationships 1. Create a table for every entity 2. Create table fields for every entity’s attributes 3. Implement relationships between the tables

Section Course Has CRN Seats CourseID Title Make the Schema Course CourseID Title Section CRN Seats Location CourseID Location

Faculty Course Teaches FacultyID First name Last Name Last Name Course Number Course name Semester Describe the relationship in this ERD (Notice the many:many Relationship)

Create the Schema: Rules Primary key field of “1” table put into “many” table as foreign key field 1:many relationships Relationship Becomes its Own Table Has many:1 relationships with original tables many:many relationships Primary key field of one table put into other table as foreign key field 1:1 relationships 1. Create a table for every entity 2. Create table fields for every entity’s attributes 3. Implement relationships between the tables

Faculty Course FacultyID First name Last Name Last Name Course Number Course name Semester When Implementing Many:Many Relations in a Schema, Conceptually you are Doing This… Faculty_Course FacCourse ID Has NOTE: NOT A VALID ERD

Faculty FacultyID FirstName LastName Course CourseNumber CourseName Faculty-Course FacultyCourseID FacultyID CourseNumber Semester FacultyCourseIDFacultyIDCourseIDSemester 1510Spring Fall Spring Fall 2011 Converting that ERD into a schema

SQL Out SQL SELECT from 1 or Multiple Tables What is a JOIN really? ORDER BY, GROUP BY, MIN(), MAX()

SELECT from 1 Table SELECT field1, field2, … FROM table1 WHERE condition1 AND condition2 AND … – Retrieves field1, field2, etc. from table1 where condition1, condition2, etc. are met. Example: SELECT * FROM faculty_course WHERE FacultyID = 3 FacultyCourseIDFacultyIDCourseIDSemester 3310Spring Fall 2011

SELECT from N Tables SELECT field1, field2, … FROM table1, table2 WHERE join_condition AND condition1 AND condition2 AND … – Retrieves field1, field2, etc. from table1, table2 where records are related to one another, and where condition1, condition 2 are met. Example: SELECT LastName, Semester FROM faculty, faculty_course WHERE faculty.facultyID = faculty_course.facultyID

What Happens For a JOIN Really? SELECT * FROM table1, table2 – Fetches every possible combination (pair) of records from table 1 and table 2, displays all fields Table 1 Record 1 Record 2 Record 3 Table 2 Record 1 Record 2 Results T1.Record 1T2.Record 1 T1.Record 1T2.Record 2 T1.Record 2T2.Record 1 T1.Record 2T2.Record 2 T1.Record 3T2.Record 1 T1.Record 3T2.Record 2

OwnerIDName StreetCityStateZip 1Pete Front St.New YorkNY Tom Dock St.PhiladelphiaPA Sandy Bloor St.WashingtonDC Jim Carlton St.SeattleWA Joe Bathurst St.BostonMA09134 JOIN with No Conditions PetIDOwnerID NameWeightType 12 Rex40Dog 22 Snowball10Cat 34 Goldie1Fish 41 Lizzy6Lizard SELECT * FROM pet, owner

PetID NameWeightType OwnerID NameStreetCityStateZip 1Rex40Dog 21 PeteFront St.New YorkNY Rex40Dog 22 TomDock St.PhiladelphiaPA Rex40Dog 23 SandyBloor St.WashingtonDC Rex40Dog 24 JimCarlton St.SeattleWA Rex40Dog 25 JoeBathurst St.BostonMA Snowball10Cat 21 PeteFront St.New YorkNY Snowball10Cat 22 TomDock St.PhiladelphiaPA Snowball10Cat 23 SandyBloor St.WashingtonDC Snowball10Cat 24 JimCarlton St.SeattleWA Snowball10Cat 25 JoeBathurst St.BostonMA Goldie1Fish 41 PeteFront St.New YorkNY Goldie1Fish 42 TomDock St.PhiladelphiaPA Goldie1Fish 43 SandyBloor St.WashingtonDC Goldie1Fish 44 JimCarlton St.SeattleWA Goldie1Fish 45 JoeBathurst St.BostonMA Lizzy6Lizard 11 PeteFront St.New YorkNY Lizzy6Lizard 12 TomDock St.PhiladelphiaPA19122

OwnerIDName StreetCityStateZip 1Pete Front St.New YorkNY Tom Dock St.PhiladelphiaPA Sandy Bloor St.WashingtonDC Jim Carlton St.SeattleWA Joe Bathurst St.BostonMA09134 JOIN Conditions in WHERE clause PetIDOwnerID NameWeightType 12 Rex40Dog 22 Snowball10Cat 34 Goldie1Fish 41 Lizzy6Lizard SELECT * FROM pet, owner WHERE pet.ownerID = owner.ownerID

PetID NameWeightType OwnerID NameStreetCityStateZip 1Rex40Dog 21 PeteFront St.New YorkNY Rex40Dog 22 TomDock St.PhiladelphiaPA Rex40Dog 23 SandyBloor St.WashingtonDC Rex40Dog 24 JimCarlton St.SeattleWA Rex40Dog 25 JoeBathurst St.BostonMA Snowball10Cat 21 PeteFront St.New YorkNY Snowball10Cat 22 TomDock St.PhiladelphiaPA Snowball10Cat 23 SandyBloor St.WashingtonDC Snowball10Cat 24 JimCarlton St.SeattleWA Snowball10Cat 25 JoeBathurst St.BostonMA Goldie1Fish 41 PeteFront St.New YorkNY Goldie1Fish 42 TomDock St.PhiladelphiaPA Goldie1Fish 43 SandyBloor St.WashingtonDC Goldie1Fish 44 JimCarlton St.SeattleWA Goldie1Fish 45 JoeBathurst St.BostonMA Lizzy6Lizard 11 PeteFront St.New YorkNY Lizzy6Lizard 12 TomDock St.PhiladelphiaPA19122

PetID NameWeightType OwnerID NameStreetCityStateZip 1Rex40Dog 21 PeteFront St.New YorkNY Rex40Dog 22 TomDock St.PhiladelphiaPA Rex40Dog 23 SandyBloor St.WashingtonDC Rex40Dog 24 JimCarlton St.SeattleWA Rex40Dog 25 JoeBathurst St.BostonMA Snowball10Cat 21 PeteFront St.New YorkNY Snowball10Cat 22 TomDock St.PhiladelphiaPA Snowball10Cat 23 SandyBloor St.WashingtonDC Snowball10Cat 24 JimCarlton St.SeattleWA Snowball10Cat 25 JoeBathurst St.BostonMA Goldie1Fish 41 PeteFront St.New YorkNY Goldie1Fish 42 TomDock St.PhiladelphiaPA Goldie1Fish 43 SandyBloor St.WashingtonDC Goldie1Fish 44 JimCarlton St.SeattleWA Goldie1Fish 45 JoeBathurst St.BostonMA Lizzy6Lizard 11 PeteFront St.New YorkNY Lizzy6Lizard 12 TomDock St.PhiladelphiaPA19122

Order By, Group By ORDER BY: – Lists records in ascending or descending order, based on the specified field – Default is ascending (ASC). Specify DESC to make it descending. GROUP BY: – Return the SELECT results for each categorical value (group) in the specified field – One result is returned for each group

PetID NameWeightType OwnerID NameStreetCityStateZip 3Goldie 1 Fish44JimCarlton St.SeattleWA Lizzy 6 Lizard11PeteFront St.New YorkNY Snowball 10 Cat22TomDock St.PhiladelphiaPA Rex 40 Dog22TomDock St.PhiladelphiaPA19122 SELECT * FROM pet, owner WHERE pet.ownerID = owner.ownerID ORDER BY weight ASC – DESC instead of ASC would reverse the order SELECT count(*) FROM pet, owner WHERE pet.ownerID = owner.ownerID GROUP BY city Count(*) City 1Seattle 1New York 2Philadelphia

Min(), Max() SELECT min(field1), field2 FROM table – Returns 1 record; the smallest value in column “field1” and the first value in column “field2” SELECT field FROM table ORDER BY field – Returns all values, but the smallest one will appear first – Safer, because “min(field1)” and “field2” result probably don’t come from the same record!! SELECT max(field) FROM table – Works the same way, but gives biggest value