SQL Lab 1

advertisement
SQL Lab 1
Basic navigation and SELECT statements in Oracle
From your desktop click on the WebFx
Applications icon
On the next screen, locate and access the
Oracle folder. Navigate to the Application
Development folder and click on the SQL
Plus icon.
You should see a log in screen that looks
like the one to the right. Input:
User ID: your email address up to the @
Password: firstinitiallastname (all lower
case)
Host: infodb2
Remember, you are using the following database, and all of the following queries are based on it. Remember: each time you reference a table,
you must preface with nfoshay.
Basic Navigation:
What happens when you press the ENTER key (answer below)
You enter all of your commands on the
SQL Command Line ‘SQL>’
Oracle SQL* plus responds with “2”
Type the following command exactly as
displayed.
SELECT * from nfoshay.building
On the line displayed, type the character
;
Every SQL command entered on the
Oracle command line must end with a
semi-colon.
Copy and paste the results of your query in the space below. What is this select statement doing?
BC BUILDING
-- -------------------AG Augustine
AX Annex
AQ Aquinas
AR Art Building
BB Bruce Brown
BT Bauer Theatre
EG Engineering
IM Immaculata Hall
NH Nicholson Hall
MH Morrison Hall
OC Oland Centre
BC BUILDING
-- -------------------PS Physical Sciences
SC Schwartz
GM Gilmora
CA Camden
MA Marguerite
MB Mount St.Bernard
From your desktop, locate and launch the
Notepad application (it’s in accessories).
The select statement is listing all instances of buildings in descending alphabetical order.
What is this query doing?
This query is listing all sections taking place in 2009 with bcode 'EG’
In notepad, create the following
command:
SELECT * from nfoshay.section
WHERE Year=2009 and
bcode=’EG’;
How many rows does it return?
21 rows returned
Copy and paste this command into
SQLPLUS and execute it.
Notepad is a good application for creating
SQL commands and keeping a record of
them.
Return to your query in Notepad. Modify
the query (or create a copy) as follows:
SELECT DISTINCT CourseNo from
nfoshay.section
WHERE Year=2009 and
bcode=’EG’;
Return to Notepad and modify the query
What is this select statement doing, specifically?
The statement is listing all distinct course numbers taking place in 2009 with bcode ‘EG’
How many rows are returned?
16 rows are returned
What is different from the previous query?
as follows (or create a copy):
In this query the results are sorted by course number in ascending order
SELECT DISTINCT CourseNo from
nfoshay.section
WHERE Year=2009 and
bcode=’EG’
ORDER BY CourseNo;
Return to Notepad and modify the query
as follows (or create a copy):
What is different from the previous query?
SELECT DISTINCT CourseNo from
nfoshay.section
WHERE Year=2009 and
bcode=’EG’
ORDER BY CourseNo DESC;
In this query the results are sorted by course number in descending order
In Notepad, create a query on the Section
table to retrieve a distinct list of all of the
rooms in the Annex sorted in ascending
order. Note: you may need to run a query
on the building table first to find the
building code for the Annex.
Type your SLQ statement here:
SELECT DISTINCT RoomNo FROM nfoshay.section WHERE bcode='AX' ORDER BY RoomNo ASC;
How many rooms are there in the Annex?
4
Cut and paste your results below:
ROOMNO
-----113
124
23A
8
In Notepad, modify the query above to
only select distinct rooms in Nicholson Hall
for Information Systems courses. Note
Type your SQL command here:
SELECT DISTINCT RoomNo FROM nfoshay.section WHERE bcode='NH' AND DeptCode='Info'
ORDER BY RoomNo ASC;
that you may need to run a query on the
Dept table first in order to run this query.
Create a query to list all of the course
names, in descending order, taught by the
Information Systems department.
How many rooms meet this criteria?
8 rooms were returned
Cut and Paste your results below:
COURSENAME
-----------------------------Web-Based Programming
Topics in Information Systems
Systems Design
Systems Analysis
Research Project for Majors
Project Management & Practice
Programming & Data Structures
Introduction to Multimedia
Intro to Programming Concepts
Intro to Elect Commerce & ERP
Intro Ent Resource Planning
COURSENAME
-----------------------------Information Systems Concepts
Info Sys Hardware & Software
Impl Conf & use of ERP
Honours Thesis
Geographic Info Systems
Electronic Business
Database Management Systems
Comput & Business Applications
Client/Server & Intranets
Business Process Integration
Bus Data Comm Sys & Networks
COURSENAME
------------------------------
Adv Database Management System
Create a query on the Section table to
retrieve CRN, CourseNo and DeptCode for
all of the classes taught in 2009 in room
138 sorted by course number in
descending order.
From the student table, select first and last
name that have the last name Smith and
sort by first name.
Type your SQL statement here.
SELECT CRN, CourseNo, DeptCode FROM nfoshay.section WHERE year=2009 AND
RoomNo='138' ORDER BY CourseNo DESC;
How many rows were returned?
14 rows were returned
Type your SQL statement here:
SELECT FName, LName FROM nfoshay.student WHERE LName='Smith' ORDER BY FName ASC;
How many rows were returned?
32 rows were returned
What is the most common first name?
Christopher
Download