Directions:
Type your answers and submit any files you create as well as
a log of your session via the digital drop box.
We will use the "cs1db" database. You will probably have
to modify an Oracle file so it knows where to find cs1db.
in "c:/program files/orawin95/network/admin/tnsnames.ora"
change entry "labdb" to read "cs1db"
the Host line to be (Host = pizza.mcs.csuhayward.edu)
{sid=labdb} to read {sid=cs1db}.
Start a log of your work by clicking on the File menu, then the Spool option, and finally the "Spool File ..." option. Note that SQLPLus doesn't like spaces in the name of the spool file -- saving to the root directory of the C: drive is the easiest way to handle it. Please include your name in the name of the spool file, like "JohnSmithSQL_Lab" (the file type is "lst").
Create a schema (in this case, a part of the database)
which allows you to define tables. You are limited to
just one schema which goes by your login name (the default).
The command is:
create schema authorization <your userid>;
Note that the SQL commands will require a semicolon, while SQLPlus
commands do not. You'll notice this because if you don't enter
the semicolon, you will get a prompt with the next line number.
If you make a typing mistake, you can enter the SQLPlus
edit
command, which will open up an editor (probably Notepad) with
the contents of the current command buffer. You can edit it and save
the modifications, then exit the editor. When you get the prompt in
the SQLPlus window, enter
run
to execute the statement.
If you should want to clear the tables for some reason, see the Updates and constraints section below.
[Note: If you want to drop a table and find you cannot because there are other
records that reference records in this table, you will need to "cascade" the
effects as follows:
drop table Department cascade constraints;
You don't have to do this step, of course :)]
You can also modify existing tables using SQL's alter table command.
There is an example of this in CreateCompany.sql where the foreign
key constraint on DNo is added. (You should understand why we couldn't put
it in the definition of Employee. Marginal hint: C++ programmers will
understand this better than those who only know Java.) Add an attribute
Certified to the Employee table by entering the following:
alter table Employee add Certified char(1)
check (Certified in ('Y', 'N'));
You will also update one of the records to include a value for this new attribute.
update Employee set Certified = 'Y'
where SSN = 123456789;
Discuss your answers to the last 3 queries with a fellow student. It can be educational to see what other approaches are possible.
If you type quit or exit in SQLPlus, it will exit the program and save the logfile. Turn in your logfile via the digital drop box.