Database Design 1 CMS 476 Dr. Karl Horak, Instructor.

Slides:



Advertisements
Similar presentations
Database Design Week 10.
Advertisements

INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
JavaScript, Third Edition
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Lecture 2: Topics Bits and Bytes Primitive Types Casting Strings Boolean expressions.
Inner join, self join and Outer join Sen Zhang. Joining data together is one of the most significant strengths of a relational database. A join is a query.
Database Systems Lecture 5 Natasha Alechina
Tables. Any database must contain one or more tables, because that’s where the data is stored. For any table there are two views provided: Datasheet view.
Oracle Data Definition Language (DDL)
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
SESSION 5.1 In this session we will be exploring Pattern Match Queries List-Of-Values Queries, Non-Matching Values in Queries Both the “And” and the “OR”
DAY 16: ACCESS CHAPTER 2 Tazin Afrin October 10,
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
Database Design 1 CMS 476 Dr. Karl Horak, Instructor.
CIS162AD - C# Decision Statements 04_decisions.ppt.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Analyzing Data For Effective Decision Making Chapter 3.
Lesson 2.  To help ensure accurate data, rules that check entries against specified values can be applied to a field. A validation rule is applied to.
IE 423 – Design of Decision Support Systems Database development – Relationships and Queries.
Input, Output, and Processing
SQL, Data Storage Technologies, and Web-Data Integration Week 2.
1 Intro to JOINs SQL INNER JOIN SQL OUTER JOIN SQL FULL JOIN SQL CROSS JOIN Intro to VIEWs Simple VIEWs Considerations about VIEWs VIEWs as filters ALTER.
Database Design 1 CMS 476 Fall 1, 2007 Dr. Karl Horak, Instructor.
Chapter 6 SQL: Data Manipulation (Advanced Commands) Pearson Education © 2009.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Concepts of Database Management Seventh Edition
Structured Query Language Chris Nelson CS 157B Spring 2008.
IMS 4212: Intro to SQL 1 Dr. Lawrence West, Management Dept., University of Central Florida Introduction to SQL—Topics Introduction to.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
M1G Introduction to Database Development 5. Doing more with queries.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Computer Science & Engineering 2111 Querying a Database 1CSE 2111 Lecture- Querying a Database.
WHAT IS A DATABASE? A DATABASE IS A COLLECTION OF DATA RELATED TO A PARTICULAR TOPIC OR PURPOSE OR TO PUT IT SIMPLY A GENERAL PURPOSE CONTAINER FOR STORING.
IE 423 – Design of Decision Support Systems Database development – Building Tables
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
Relational Database Techniques
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Access Queries Agenda 6/16/14 Review Access Project Part 1, answer questions Discuss queries: Turning data stored in a database into information for decision.
Mr C Johnston ICT Teacher
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Web Programming MySql JDBC Web Programming.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Working with MySQL. SWC – Creating tables We know how to create a database in MySQL – an empty database Next step is to add tables to the database.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
DAY 14: ACCESS CHAPTER 1 RAHUL KAVI October 8,
Thinking in Sets and SQL Query Logical Processing.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Objectives Identify solutions of inequalities Graphing Inequalities
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Multiple variables can be created in one declaration
ICT Database Lesson 2 Designing a Database.
ESRM 250/CFR 520 Autumn 2009 Phil Hurvitz
Presentation transcript:

Database Design 1 CMS 476 Dr. Karl Horak, Instructor

Session 3 Week in Review Week in Review Application du Jour Application du Jour Lecture: Lecture: –Delimiters –Logical operators and expressions –Multiple table queries Demonstration: AND, OR, NOT & Null Demonstration: AND, OR, NOT & Null Demonstration: Relationships & Joins Demonstration: Relationships & Joins Exercises Exercises

Week in Review In a word, frantic RPT goes to Merry Old England RPT goes to Merry Old England Web portal end-of-FY deadline Web portal end-of-FY deadline On-going portals On-going portals

Lecture Topic A: Delimiters Most compilers (and database engines) never allow variables to begin with a digit (or a minus sign). Most compilers (and database engines) never allow variables to begin with a digit (or a minus sign). Hence, anything starting with a digit is either: Hence, anything starting with a digit is either: –An integer or –Floating point Things beginning with characters can be all sorts of other stuff Things beginning with characters can be all sorts of other stuff

Delimiters Things with digits or +/- signs are always numeric. Things with digits or +/- signs are always numeric. Everything else needs to be characterized for the database engine. Everything else needs to be characterized for the database engine. –[xyz] in Access indicates that xyz is a field name or a parameter (more on that later) –“xyz” and ‘xyz’ tell the system that xyz is a string of characters –#1/26/53# is how one indicates a date in Access Otherwise, the database engine divides 1 by 26 by 53 and you get a mess Otherwise, the database engine divides 1 by 26 by 53 and you get a mess Actually, you get Actually, you get

String Delimiters ‘Moby Dick’—a string ‘Moby Dick’—a string “Moby Dick”—a string “Moby Dick”—a string [Moby Dick]—the Moby Dick(!) field [Moby Dick]—the Moby Dick(!) field but “Prisoner’s Dilemma” is needed for an embedded single apostrophe but “Prisoner’s Dilemma” is needed for an embedded single apostrophe ‘Prisoner’s Dilemma’ returns an error for unmatched delimiters ‘Prisoner’s Dilemma’ returns an error for unmatched delimiters [First Name] will indicate a field name, parameter, or variable [First Name] will indicate a field name, parameter, or variable Hint: Omit spaces in field names and [ ] are not needed Hint: Omit spaces in field names and [ ] are not needed

Dates and Times While we’re talking about dates: –‘<’ (less than) is “before” –‘>’ (greater than) is “after” Always remember and don’t ever forget: –Dates are stored as floating point numbers, usually based on the number of days since something like January 1, 1900 –Times are stored as decimal fractions of a day 6:00 AM is 1/4 of a day, so its :00 AM is 1/4 of a day, so its 0.25 Some time functions are accurate to seconds Some time functions are accurate to seconds Other time functions are accurate to milliseconds Other time functions are accurate to milliseconds

Intervals An interval has: A start time A start timeAND A finish time A finish timeExample: #1/1/1714# <= Mydate <= #3/26/1837# or (#1/1/1714# <= Mydate) AND (Mydate <= #3/26/1837#)

Lecture Topic B: Logical Operators and Expressions Only two values in Boolean logic: Only two values in Boolean logic: –True & False –Yes & No –On & Off –0 & -1* But then there’s that pesky Null thingie But then there’s that pesky Null thingie * Clever trick #437: Often any non-zero value is treated as True

Boolean Operators AND—True if both are true AND—True if both are true OR—True if either or both are true OR—True if either or both are true NOT—True  False & False  True NOT—True  False & False  True XOR—Exclusive OR; rarely seen, true if either one or the other but not both are true XOR—Exclusive OR; rarely seen, true if either one or the other but not both are true

Venn Diagrams NOT p = True Not(p) = Truep = False

AND p = True q = True p and q

OR p = True q = True p or q

XOR p = True q = True p xor q What the heck is this gray area?

Some more examples p = True q = True r = True A? D? B? C?

Boolean Logic in the QBE SELECT [IT survey].Name FROM [IT survey] WHERE ([IT survey].Staff=False AND [IT survey].A<>False) OR ([IT survey].Staff=False AND [IT survey].B<>False);

Null An unknown value An unknown value Not 0 Not 0 Neither true nor false Neither true nor false Not an empty string, “” Not an empty string, “” Not ASCII 0 (or \0) Not ASCII 0 (or \0) Not /dev/null Not /dev/null Not a Nil pointer Not a Nil pointer Frankly, its not anything except Null Frankly, its not anything except Null Almost any operation or function on Null will return a surprising and often incorrect value Almost any operation or function on Null will return a surprising and often incorrect value Tests for Null values Tests for Null values –Isnull() in expressions –‘Is Null’ in WHERE clauses

Operations on Null A = Null is neither True nor False A = Null is neither True nor False A <> Null is neither True nor False A <> Null is neither True nor False Null and False = False Null and False = False Null or True = True Null or True = True

Lecture Topic C: Multi-table Queries—Joins Observation #1—You can keep adding tables (and queries) to the QBE grid Observation #1—You can keep adding tables (and queries) to the QBE grid What is the percentage of Iranian enrichment capacity relative to the U.S?

Joining Tables Observation #2—You can drag-and- drop lines connecting tables in the QBE grid Observation #2—You can drag-and- drop lines connecting tables in the QBE grid What are the enrichment facilities in Western Europe?

Relationships Observation #3—You can connect more than two tables in the QBE grid Observation #3—You can connect more than two tables in the QBE grid What are the enrichment facilities in Europe?

Key Fields The “key” to joining tables is to have common information that references the same data in each table. The “key” to joining tables is to have common information that references the same data in each table. A “primary key” is a unique identifier for a record. A “primary key” is a unique identifier for a record. A “foreign key” is used as a look-up value and matches a primary key in another table. A “foreign key” is used as a look-up value and matches a primary key in another table.

Compound Keys Keys may be made up of more than one field Keys may be made up of more than one field [Last Name] + [First Name] [State] + [City] Keys may include expressions Keys may include expressions Left([Last Name],1)

Relationships A “relationship” means that there are corresponding primary and foreign keys between tables. A “relationship” means that there are corresponding primary and foreign keys between tables. Temporary relationships may be created “on the fly” in the QBE Temporary relationships may be created “on the fly” in the QBE Permanent relationships may be created with the Tools | Relationships Permanent relationships may be created with the Tools | Relationships

Joining Tables with Where Clauses* SELECT [EFAC data].[Plant Name/Location], MemberStates.IAEAregion FROM [EFAC data], MemberStates WHERE [EFAC data].Country = MemberStates.Country; * Access will automatically convert these into JOIN statements

Inner Joins SELECT [EFAC data].[Plant Name/Location], MemberStates.IAEAregion FROM [EFAC data] INNER JOIN MemberStates ON [EFAC data].Country = MemberStates.Country;

Outer Joins May be either Left or Right Joins May be either Left or Right Joins SELECT [EFAC data].[Plant Name/Location], MemberStates.Country FROM [EFAC data] LEFT JOIN MemberStates ON [EFAC data].Country = MemberStates.Country;

Use the Force, Luke Left Join Inner Join

Kick it up another notch NB: All arrows “point” in the same direction.

Gives you… SELECT [EFAC data].[Plant Name/Location], Continents.Continent FROM ([EFAC data] LEFT JOIN MemberStates ON [EFAC data].Country = MemberStates.Country) LEFT JOIN Continents ON MemberStates.IAEAregion = Continents.IAEAregion;

Next Week Database Design & Relationships Database Design & Relationships –Modeling Relationships –Entity-Relationship (ER) Diagrams –Normalization 3 rd Normal Form 3 rd Normal Form –Object-Role Modeling for perfect 3NF

Demonstration Boolean expressions Boolean expressions Date logic Date logic Relationships—Joins Relationships—Joins (Download new version—lots of new tables are included.)

Exercises and Q&A 1. List all the inventions created between 1835 and 1845 inclusive along with their inventors. 2. Which was invented first, the microscope or the thermometer? 3. Who invented the seed drill? (What the heck is a ‘seed drill’ anyway?) 4. Did DeGuerre (of DeGuerrotype fame) invent photography? 5. Claude Bernard is rarely credited with inventing what process with a more famous colleague?

More Exercises 6. List the names of those in IT who are also in Distribution Group A. 7. List the names of staff who are characterized as ‘B’. 8. List all those in ‘C’ or those who did not respond (neither in ‘A’, ‘B’, nor ‘C’). 9. Who has a ‘K’ or ‘k’ in their name? 10. Provide a list of persons sorted by first name.

Still More Exercises 11. List employees and their department names and locations. 12. List all departments, including one without any current employees. 13. Draw a map of the five hypothetical countries showing which ones are adjacent. 14. In the Inventions table, write a query that will fill in the columns Year and Inventor from the original Scratch field (copied out of Wikipedia)