Upload
tess98
View
142
Download
0
Tags:
Embed Size (px)
Citation preview
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 AnatomyA 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 ViewList 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 SalespersonSELECT ename FROM SalespersonSELECT 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
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.salesdateFROM Salesperson INNER JOIN OrdersON Salesperson.empid = Orders.empidWHERE Salesperson.empid AND Orders.empid = 10
orderid salesdate ename rank
1185 Feb 7, 05 Mary 4
1183 Feb 6, 05 Mary 4
1180 Feb 5, 05 Mary 4
Summary Databases
SQL & Querying Reports
Next class (Monday): Security and Social Issues
Office Hours today! Lab #2 Due Friday!