databases ii
TRANSCRIPT
![Page 1: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/1.jpg)
Databases
Lab #2 Prep Continued
![Page 2: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/2.jpg)
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
![Page 3: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/3.jpg)
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
![Page 4: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/4.jpg)
Database AnatomyA record is the information relating to one person, product, or event
A field is a discrete chunk of information in a record
![Page 5: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/5.jpg)
Database Anatomy
The view is a display of the information in fields based on a particular layout of field data.
Form ViewList View
![Page 6: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/6.jpg)
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.
![Page 7: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/7.jpg)
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
![Page 8: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/8.jpg)
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.
![Page 9: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/9.jpg)
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!
![Page 10: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/10.jpg)
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!
![Page 11: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/11.jpg)
The Nature of SQL Definition: SQL - Structured Query
Language and more SQL - a declarative language
![Page 12: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/12.jpg)
![Page 13: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/13.jpg)
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
![Page 14: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/14.jpg)
Music
![Page 15: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/15.jpg)
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
![Page 16: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/16.jpg)
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.
![Page 17: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/17.jpg)
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.
![Page 18: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/18.jpg)
The Inner Join SELECT fields….
FROM <table reference> INNER JOIN
<table reference> ON <search
condition>
![Page 19: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/19.jpg)
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
![Page 20: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/20.jpg)
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
![Page 21: Databases II](https://reader035.vdocument.in/reader035/viewer/2022062319/556131fcd8b42aa2118b49b7/html5/thumbnails/21.jpg)
Summary Databases
SQL & Querying Reports
Next class (Monday): Security and Social Issues
Office Hours today! Lab #2 Due Friday!