This document was written by CS 290W TA David Corcoran and was last modified
An Oracle Database contains the following:
Database: StudentGrades
StudentID | FullName | Login | Password |
302-01-1341 | David Corcoran | corcoran | dave123 |
404-09-2323 | James Billy | billyj | cool |
234-02-2333 | Jim Bob | jimbob | school |
StudentID | Homework1 | Homework2 | Exam1 |
302-01-1341 | 78 | 47 | 98 |
404-09-2323 | 72 | 64 | 93 |
234-02-2333 | 38 | 22 | 21 |
The database StudentGrades contains two tables. The first one is Access and the second is Grades. Both are related because they both contain the student ID. This makes the tables relational. We could verify the username and password by using table Access and use the corresponding student ID to query the table Grades. Both tables are related to one another and belong to database StudentGrades.
All of this will become relevant when we discuss doing actual queries
of database tables using Perl. For example with the SELECT one can
query a database. But you can only have it return certain rows or
just have it do comparisons with certain rows. The syntax of the
SELECT statement is:
SELECT fields FROM table WHERE criteria;
Much more information about the SQL SELECT statement may be found in
Introduction to Structured Query Language.
Consider the following example:
SELECT Homework1 FROM Grades WHERE
StudentID = '302-01-1341';
We are asking to return only column Homework1 from the table Grades where
the Column StudentID contains 302-01-1341. The result of this query will
be the number 78. See if you can understand the following:
SELECT Exam1, Homework2 FROM Grades WHERE
StudentID = '404-09-2323';
SELECT * FROM Grades WHERE Homework2 < 50;
SELECT * FROM Grades WHERE
Homework1 = 78 AND Homework2 = 47;
SELECT FullName, Login FROM Access WHERE
Password LIKE '%ool%';
SELECT Homework1, Homework2, Exam1 FROM Grades
WHERE StudentID =
(SELECT StudentID FROM Access WHERE
Login = 'corcoran' AND Password = 'dave123');