Вы находитесь на странице: 1из 12

0TASK 1

(A)
LEXIS CAR RENTALS
LEXIS CAR RENTALS is firm which is into the renting of cars and wants to develop a database
system to monitor its customers, rentals, and their locations.
A car may belong to one vehicle category. Every category is described by a unique ID
number, a label and a detailed description of the category. LEXIS RENTALS has so many
offices in Ghana. Each location has a unique ID number, address (Region, city, number,
street) and more telephone numbers. LEXIS RENTALS also keeps records of its customers in
the database. A customer is described by a unique ID number, SSN, Name (first and Last
name), Region, email, mobile number and the city he or she lives. Customers rent a car,
which they move it from one location to another. A rental is also described by a unique
reservation number, rental amount, a Pickup date and a return date.
ADVANTAGES OF THE DATABASE SYSTEM

a. The DBMS will help the organization to categorize and structure all available data.

b. The DBMS is versatile; it is versatile because it can be accessed on computers, tablets,


and smart phones whenever the firm wants to access.

ENTITIES IN THE SCENARIO

 Car
 Car Type
 Reservation
 Customer
 Rental
 LEXIS OFFICES
(B) ENTITY RELATIONSHIP DIAGRAM NORMALISED TO THE 3RD NORMAL FORM
Name Attributes Data Type Value Constraint

CUSTOMERS ‘Customer_id` Int 11 Primary Key


`ssn`  Int 11 NOT NULL
`First_name`  Varchar 45
`Last_name`  Varchar 45 Default ‘0.00’
`Mobile’ char 45
‘Region’ Varchar 45
`city`  Varchar 45
`Street` Varchar 45
`email`  VARCHAR 40

RESERVATION ‘Reservation_ID’ Varchar 3 Primary Key


‘Amount double’ money 6,2
‘Pickup date’ datetime
‘Return_ date’ datetime
‘Pickup _Location ID Varchar 3
‘Return_location ID’ Varchar 3
‘Customer_ID’ INT 11 Foreign key
‘Car_ID’ INT 3 Foreign Key

‘Car_ ID’ INT 3 Primary Key


‘CurrentLocation_ ID’ Varchar 3
‘Type_ID’ INT 4 Foreign key
CAR ‘Color’ Varchar 45
‘Brand’ Varchar 45
‘Model’ Varchar 45
‘description’ Varchar 45 Default ‘0.00’
‘Purchase_date’ Varchar 45
Date

CAR_TYPE ‘Type _ID’ INT 4 Primary Key


‘ Type _Label’ Varchar 45
‘Type_description’ Varchar 45

OFFICE officeID INT 3 Primary Key


carID INT 3 FOREIGN KEY
Region Varchar 45
City Varchar 45
number Varchar 11
street INT
default_telephone
TASK 2
SQL SYNTAXES FOR TABLE CREATION AND POPULATION OF TABLES
--
-- Database: `car`
--

-- --------------------------------------------------------

--
-- Table structure for table `car`
--

CREATE TABLE `car` (


`carID` int(11) NOT NULL,
`typeID` int(11) NOT NULL,
`brand` varchar(50) DEFAULT NULL,
`model` varchar(40) DEFAULT NULL,
`color` varchar(50) DEFAULT NULL,
`description` varchar(40) DEFAULT NULL,
`purchdate` datetime DEFAULT NULL,
`currentlocationID` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `car`
--

INSERT INTO `car` (`carID`, `typeID`, `brand`, `model`, `color`, `description`,


`purchdate`, `currentlocationID`) VALUES
(20, 90, 'toyota', 'gt502', 'black', 'for uber purposes', '2020-07-01 00:00:00',
12),
(21, 110, 'nissan', 'n-456', 'ash', 'for hiring purposes', '2020-07-02 00:00:00',
13),
(22, 100, 'bugatti', 'bu-g78', 'blue', 'racing and sports', '2020-07-03 00:00:00',
14);

-- --------------------------------------------------------

--
-- Table structure for table `car_type`
--

CREATE TABLE `car_type` (


`typeID` int(11) NOT NULL,
`typeLabel` varchar(50) DEFAULT NULL,
`typeDescr` varchar(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `car_type`
--
INSERT INTO `car_type` (`typeID`, `typeLabel`, `typeDescr`) VALUES
(90, 'sedan', 'has four doors'),
(100, 'sports car', 'sleek and cool'),
(110, 'coupe', 'two doors');

-- --------------------------------------------------------

--
-- Table structure for table `customer`
--

CREATE TABLE `customer` (


`customerID` int(11) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`city` varchar(40) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`region` varchar(50) DEFAULT NULL,
`mobile` char(10) DEFAULT NULL,
`SSN` varchar(14) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `customer`
--
INSERT INTO `customer` (`customerID`, `name`, `city`, `email`, `region`,
`mobile`, `SSN`) VALUES
(700, 'jerry prichard', 'tema', 'jerpr@yahoo.com', 'greater accra', '0245678900',
'JP00567H2'),
(710, 'braun strowman', 'ashaiman', 'brstrow@gmail.com', 'greater accra',
'0202590894', 'BS26756UH'),
(720, 'bruce willis', 'dansoman', 'brwilli@gmail.com', 'greater accra',
'0245678906', 'BR-23457S');

-- --------------------------------------------------------

--
-- Table structure for table `office`
--

CREATE TABLE `office` (


`officeID` int(11) NOT NULL,
`phone` char(10) DEFAULT NULL,
`address` varchar(30) DEFAULT NULL,
`carID` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `office`
--

INSERT INTO `office` (`officeID`, `phone`, `address`, `carID`) VALUES


(61, '0234567890', 'p.o. box 45', 22),
(62, '0245678987', 'p.o. box 565', 21),
(63, '0567898765', 'p.o. box fr 786', 20);

-- --------------------------------------------------------

--
-- Table structure for table `reservation`
--

CREATE TABLE `reservation` (


`reservationID` int(11) NOT NULL,
`carID` int(11) NOT NULL,
`customerID` int(11) NOT NULL,
`pickuplocationID` int(11) DEFAULT NULL,
`returnDate` datetime DEFAULT NULL,
`pickupDate` datetime DEFAULT NULL,
`returnlocationID` int(11) DEFAULT NULL,
`amount` decimal(6,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `reservation`
--
INSERT INTO `reservation` (`reservationID`, `carID`, `customerID`,
`pickuplocationID`, `returnDate`, `pickupDate`, `returnlocationID`, `amount`)
VALUES
(90, 20, 720, 999, '2020-07-07 00:00:00', '2020-07-01 00:00:00', 880,
'7550.00'),
(501, 20, 700, 2000, '2020-07-22 00:00:00', '2020-07-04 00:00:00', 301,
'5000.00'),
(502, 21, 710, 789, '2020-07-20 00:00:00', '2020-07-06 00:00:00', 987,
'4567.00');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `car`
--
ALTER TABLE `car`
ADD PRIMARY KEY (`carID`),
ADD KEY `car_car_type_FK` (`typeID`);

--
-- Indexes for table `car_type`
--
ALTER TABLE `car_type`
ADD PRIMARY KEY (`typeID`);

--
-- Indexes for table `customer`
--
ALTER TABLE `customer`
ADD PRIMARY KEY (`customerID`),
ADD UNIQUE KEY `customer__UN` (`SSN`);

--
-- Indexes for table `office`
--
ALTER TABLE `office`
ADD PRIMARY KEY (`officeID`),
ADD KEY `office_car_FK` (`carID`);

--
-- Indexes for table `reservation`
--
ALTER TABLE `reservation`
ADD PRIMARY KEY (`reservationID`),
ADD KEY `reservation_car_FK` (`carID`),
ADD KEY `reservation_customer_FK` (`customerID`);

--
-- Constraints for dumped tables
--

--
-- Constraints for table `car`
--
ALTER TABLE `car`
ADD CONSTRAINT `car_car_type_FK` FOREIGN KEY (`typeID`) REFERENCES
`car_type` (`typeID`);

--
-- Constraints for table `office`
--
ALTER TABLE `office`
ADD CONSTRAINT `office_car_FK` FOREIGN KEY (`carID`) REFERENCES `car`
(`carID`);

--
-- Constraints for table `reservation`
--
ALTER TABLE `reservation`
ADD CONSTRAINT `reservation_car_FK` FOREIGN KEY (`carID`) REFERENCES
`car` (`carID`),
ADD CONSTRAINT `reservation_customer_FK` FOREIGN KEY (`customerID`)
REFERENCES `customer` (`customerID`);
COMMIT;

c. Some SQL Query examples

1. SELECT carID,typeLabel,brand
from car join car_type
ON car.typeID = car_type.typeID
where color = 'black';
2. SELECT * FROM `car` WHERE carID = 20;
3. SELECT COUNT(customerID) AS customerID,name ,city from customer G
ROUP BY name,city ORDER BY customerID DESC;
4. SELECT brand, address , model from car join office on office.carID = car.c
arID;
5. update car set color = 'red' WHERE color = 'black’;

Вам также может понравиться