You are on page 1of 2

Creating, Altering Tables, Loading Data

COSC 3480 Lab1

Lab. #1 (Total score: 90, Due date: 9/23/02 (Tuesday))


BestRental is a car rental company that has over 3,000 employees and many outlets. The company owns variety of vehicles in different outlets. The company maintains the vehicles in best condition by checking vehicles regularly. Mechanics check each vehicle as soon as it is returned and write a fault report. The relational schemas for the BestRental database is illustrated as follows: Outlet Attribute clientNo clientName clientStreet clientCity clientState clientZipCode clientTelNo contactName contactEmail Type number(8) varchar2(50) varchar2(40) varchar2(15) varchar2(15) varchar2(9) varchar2(20) varchar2(50) varchar2(100) Constraint pk not null and unique not null AttributeType Constraint outletNo number(8) pk outletStreet varchar2(40) not null outletCity varchar2(15) not null outletState varchar2(15) outletZipCode varchar2(9) outletTelNo varchar2(20) not null and unique managerEmployeeNo number(8) fk

not null

Vehicle AttributeType EmployeeNo Title firstName lastName address homeTelNo ssn DOB Gender Salary DateStarted OutletNo Constraint number(8) pk varchar2(10) not null varchar2(30) not null varchar2(30) not null varchar2(100) varchar2(20) char(12) not null and unique date char M or F number(8,2) not null date not null number(8) fk AttributeType VehLicenseNo VehicleMake VehicleModel Color NumDoors Capacity HireRate OutletNo Constraint varchar2(10) varchar2(15) varchar2(15) varchar2(15) number(1) number(4) number(6,2) number(8) pk not null not null not null >0 and <20 >0 and < $500 fk and not null

RentalAgreement AttributeType Constraint rentalNo number(8) pk dateStart date not null timeStart number(4,2) not null dateReturn date timeReturn number(4,2) mileageBefore number(8) mileageAfter number(8) policyNo number(15) unique and not null insuranceCoverType varchar(10) insurancePremium number(5,2)

FaultReport AttributeType VehicleNo DateChecked TimeChecked Comments EmployeeNo Constraint varchar2(10) pk and fk date pk number(4,2) not null varchar2(50) not null number(8) fk and not null

Note that pk represents a primary key and fk represents a foreign key. Remember that there should be only one primary key but there may be more than one foreign key in a table.

Creating, Altering Tables, Loading Data

COSC 3480 Lab1

In this Lab., you will implement the relational database for BestRental based on the given schemas. Useful Tips for the Labs. throughout this course Prepare your program (SQL) using the Text editor such as Note Pad. Copy and Past your program from the Text editor to SQL*Plus command line. If the program works, save the program. Otherwise, fix the error for the program in the Text editor and try it again. Save your text file regularly before you lose what you have typed. You can also save the result of your commands using SPOOL command. Answer/perform the following questions/tasks: (a) (b)
(c)

(d) (e) (f) (g) (h)


(i)

(j) (k) (l) (m)

What is the SPOOL command for? Briefly explain it and give an example. [2] What is the HOST command for? Briefly explain it and give an example. [2] Create all the tables based on the given schemas for BestRental database and display the structure of each table after you created it using Oracle SQL*Plus. Make sure you implement all the necessary integrity constraints for the database. [6x5=30] Change the salary column type in Employee table to NUMBER(9,2) using the ALTER command. [2] Add the domain constraint, >0 and <10 for the Capacity column in Vehicle table using the ALTER command. [2] Change the type of clientZipCode in Client table to CHAR(9) using the ALTER command. [2] Add a new column, VehicleYear to Vehicle table using the ALTER command. [2] Remove the not null constraint for Title column in Employee table. [2] Display all the constraint names AND types for Outlet tables using the SELECT command. [4] List all the table names you created so far using the SELECT command. [2] Load all the tables for the BestRental database with at least one record for each table using the INSERT command. Make sure that your insertions do not violate common sense.[6x5=30] Show an example of UPDATE command. [2] Show an example of DELETE command. [2]

If you finished all the above exercises, make sure you keep all the commands in a file (e.g., a script file) before you lose them. (n) Drop all the tables for the BestRental database. [6]

You need to turn in:

The printed copy of Oracle commands and results (e.g., responses from Oracle) of the commands. DO NOT include the practice commands with errors. If you do, we will only obtain partial credit for your solution.

You might also like