• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Databases II

Databases II






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • The Cartesian Product is EVERY row from the customer table joined with EVERY row from the customer_location table, without regard for values in any column. The WHERE clause is used to JOIN the tables.
  • Question – what would this query show if we ran it on our Lab 2 data?

Databases II Databases II Presentation Transcript

  • Databases Lab #2 Prep Continued
  • Learning Objectives 2
    • Recognize and list the characteristics of the different components of SQL.
    • Define the basics of SQL.
    • Use SQL statements to perform simple queries.
    • Analyze ER diagrams for use in creating SQL queries
  • The Electronic File Cabinet: Database Basics
    • Database software is…
    • application software (like word processing and spreadsheet software)
    • designed to maintain databases (collections of information)
    • A Database is…
    • a collection of information stored in an organized form on a computer
  • Database Anatomy
    • A record is the information relating to one person, product, or event
    A field is a discrete chunk of information in a record
  • Database Anatomy
    • The view is a display of the information in fields based on a particular layout of field data.
    Form View List View
  • What Makes a Database Relational?
    • A database is relational when files are related to each other, such as this Student ID field in the Student file.
    If a change is made in one file, all files are updated immediately.
  • Relationships
    • Relationships illustrate how two entities share information in the database structure.
    • There are several kinds of relationships that can be established between two entities:
      • 1 to 1 Example : A student ID number identifies one and only one student
      • 1 to many Example : In one course there are many students
      • many to many Example : Many students can take many courses
  • TASK 3
    • Get familiar with Access
    • Concentrate on building your tables BASED ON YOUR SCHEMA (Entity Relationship Diagram) from TASK 2.
    • After the tables have been built and relationships set between them, build your input form and put in the data.
    • Both of these are finicky - allow plenty of time.
  • Steps in making and using a DB
    • Gather requirements
    • Design, design, design! (ER Diagram)
    • Create database
    • Input data
    • Query – ask questions of the database
    • Produce reports
    Done! To Do!
  • Querying The Database
    • Query == a question
    • How do we find:
      • All directors with a rating greater than 5?
      • All movies with a rating less than 6?
      • All the movies with a rating between 4 and 6?
      • All the movies for which the director has a rating lower than 5 but the movie has a rating greater than 4?
    • Use SQL!
  • The Nature of SQL
    • Definition: SQL - Structured Query Language and more
    • SQL - a declarative language
  • SQL Basics
    • The fully qualified attribute (column name) Artists.Ar_ID , CDs.CD_Title . Ids both table and column
    • Operators: < = > <= <> >= AND OR
    • Predicates: LIKE IN BETWEEN
  • Music
  • SQL Code - Querying the Database
      • SELECT * FROM Salesperson
      • SELECT ename FROM Salesperson
      • SELECT ename, salary FROM Salesperson WHERE salary <= 1000
      • SELECT Customers.cname, Orders.orderid, Orders.salesdate FROM Customers, Orders WHERE Customers.custid=Orders.custid
  • Examining the Select Statement
    • The SELECT command is where 80% of all SQL statements take place.
    • SELECT jobs FROM table of university jobs WHERE wage > $10.00
    • Most powerful use of SELECT - when it connects of joins two or more tables.
  • Joining Tables
    • Joins are based on the Cartesian product of two or more tables.
    • Assignment 3 wants to join 2 tables based on a common column which is identical in both tables- that of Dir_id .
    • An Dir_id entry in one table equals the same Dir_id entry in the same column of the other table.
  • The Inner Join
    • SELECT fields….
    • FROM <table reference> INNER JOIN
    • <table reference> ON <search
    • condition>
  • Inner Join Example
    • Question:
      • CD has rank better than or equal to 8
      • List CD Title and Producer Name
    • For you:
      • CD has rank less than 5
      • Has been produced in the last 7 years (since 2000)
      • Show CD Title, year, and producer name
  • Inner Join Example
    • SELECT CDs.CD_Title, Artists.LastName
    • FROM Artists INNER JOIN CDs ON Artists.Ar_ID = CDs.Ar_ID
    • WHERE
    • Artists.Ar_Rank >=9 AND CDs.CD_Rank >=8
  • The boss wants to know how many orders Mary Sanseverino (empid 10) has sold. The boss wants to see a list of orderids, the date Mary sold these orders, Mary’s name, and her rank. SELECT Salesperson.ename, Salesperson.rank, Orders.orderid, Orders.salesdate FROM Salesperson INNER JOIN Orders ON Salesperson.empid = Orders.empid WHERE Salesperson.empid AND Orders.empid = 10 4 Mary Feb 5, 05 1180 4 Mary Feb 6, 05 1183 4 Mary Feb 7, 05 1185 rank ename salesdate orderid
  • Summary
    • Databases
      • SQL & Querying
      • Reports
    • Next class (Monday):
      • Security and Social Issues
    • Office Hours today!
    • Lab #2 Due Friday!