In this assignment, you will work with the OracleTM DBMS to perform SQL queries. You will be accessing a database and designing queries to retrieve data from that database.
Oracle is one of the most widely used DBMS programs in the world. It runs on virtually every kind of computer, from PCs and Macintoshes, to minicomputers and giant mainframes. Oracle uses a relational data model and provides a form of SQL as its query language. Oracle uses an interactive interface for generating queries (SQL*PLUS) that will perform many useful functions for you.
Oracle can be accessed from either Unix or DOS (PC). Click here to find documentation on how to access Oracle and how to work in SQL*PLUS. Note that for this assignment you will need to log in to Bulldog or one of the other mainframes in order to work.
The database you will query is a Personal Address Book database. You are to write queries for the database and then spool your queries along with the results to a file. You should submit this file containing your results.
The Personal Address Book database contains four tables as follows:
PEOPLE: | Contains information about the people in the address book. The primary key is the ID. NAME is mandatory and other information like CATEGORY (values can be 'FAMILY', 'FRIENDS', 'COLLEAGUES', 'BUSINESS', 'OTHER'), BIRTHDATE, date when you met the person (MET_ON_DATE) is optional. |
TELEPHONE: | Contains information about the telephone numbers of people in the PEOPLE table. The primary key is the ID. The PEOPLE_ID is a foreign key that refers to a row in the PEOPLE table and is mandatory. The NUMBER_STRING column stores the phone number and is mandatory. TYPE_OF_NUMBER is an optional field which can only take the following values - 'HOME', 'OFFICE', 'CELL'. |
ADDRESS: | Contains the addresses of the people stored in the PEOPLE table. The primary key is ID. The PEOPLE_ID is a foreign key that refers to a row in the PEOPLE table and is mandatory. The STREET, CITY, STATE and ZIPCODE are address related columns out of which STREET, CITY and STATE are mandatory. TYPE_OF_ADD can take values 'HOME'or 'OFFICE'. |
APPOINTMENT: |
Contains information about the appointment scheuled
with a person from the PEOPLE table. The primary key is the ID. PEOPLE_ID and ADDRESS_ID are foreign keys into PEOPLE and ADDRESS
tables respectively and are mandatory. APP_DATE is a mandatory date column
that stores the date and the time of the appointment. |
The tables have been created with the following script:
CREATE TABLE PEOPLE (
ID NUMBER PRIMARY KEY,
NAME VARCHAR2(50) NOT NULL,
CATEGORY VARCHAR2(15) CHECK ( CATEGORY IN ( 'FAMILY', 'FRIENDS', 'COLLEAGUES', 'BUSINESS', 'OTHER' ) ),
BIRTHDATE DATE,
MET_ON_DATE DATE );
CREATE TABLE TELEPHONE (
ID NUMBER PRIMARY KEY,
PEOPLE_ID NUMBER NOT NULL,
NUMBER_STRING VARCHAR2(20) NOT NULL,
TYPE_OF_NUMBER VARCHAR2(10) CHECK ( TYPE_OF_NUMBER IN ( 'HOME', 'OFFICE', 'CELL' ) ),
FOREIGN KEY(PEOPLE_ID) REFERENCES PEOPLE(ID) );
CREATE TABLE ADDRESS (
ID NUMBER PRIMARY KEY,
PEOPLE_ID NUMBER NOT NULL,
STREET VARCHAR2(50)NOT NULL,
CITY VARCHAR2(20) NOT NULL,
STATE VARCHAR2(20) NOT NULL,
ZIPCODE VARCHAR2(10),
TYPE_OF_ADD VARCHAR2(10) CHECK ( TYPE_OF_ADD IN ( 'HOME', 'OFFICE' ) ),
FOREIGN KEY(PEOPLE_ID) REFERENCES PEOPLE(ID) );
CREATE TABLE APPOINTMENT (
ID NUMBER PRIMARY KEY,
PEOPLE_ID NUMBER NOT NULL,
ADDRESS_ID NUMBER NOT NULL,
APP_DATE DATE NOT NULL,
FOREIGN KEY(PEOPLE_ID) REFERENCES PEOPLE(ID),
FOREIGN KEY(ADDRESS_ID) REFERENCES ADDRESS(ID) );
The database can be accessed from the SQL prompt as follows:
To select all rows in the table PEOPLE you can use the query:
SQL> SELECT * FROM joshi031.PEOPLE;Similarly you can select all rows in other tables (TELEPHONE, ADDRESS & APPOINTMENT).
You can copy the data from each of these tables to tables you create
in your own tablespace. For example, to copy the data from the PEOPLE table
to a table named MYPEOPLE in your own tablespace execute the following query:
SQL> CREATE TABLE MYPEOPLE AS SELECT * FROM joshi031.PEOPLE;
To view all the information about a table use the query:
SQL> DESC tablename;
You should write queries for the following situations: