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
A record is the information relating to one person, product, or event
A field is a discrete chunk of information in a record
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 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
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
Design, design, design! (ER Diagram)
Query – ask questions of the database
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?
The Nature of SQL
Definition: SQL - Structured Query Language and more
SQL - a declarative language
The fully qualified attribute (column name) Artists.Ar_ID , CDs.CD_Title . Ids both table and column
Operators: < = > <= <> >= AND OR
Predicates: LIKE IN BETWEEN
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.
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
FROM <table reference> INNER JOIN
<table reference> ON <search
Inner Join Example
CD has rank better than or equal to 8
List CD Title and Producer Name
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
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