COSC 4820: Database Systems, Spring 2023
Project - Autos, Create tables
Maxwell Slingerland
04/26/2023
The database model and schema have been created. A change made
from the model to the schema was to change the onLot table to a
column in the Cars table. This change makes changing and checking if
a car is on the lot easier since another table doesn't need to be
checked each time and updated when a car is sold. For the VIN some
of the values can be null so it could not be used as a key.
Cars(
ATID CHAR(10) NOT NULL PRIMARY KEY,
stockNo VARCHAR(20),
VIN VARCHAR(30),
status ENUM('used', 'certified used', 'new),
make VARCHAR(255),
year SMALLINT,
MSRP INT,
price INT,
bodyStyle VAR CHAR(100),
doors VAR CHAR(15),
engine VAR CHAR(100),
fuelType ENUM('Gasoline', 'Diesel', 'Electric'),
exteriorColor VARCHAR(100),
interiorColor VARCHAR(100),
mileage INT,
stereo VARCHAR(100),
driveType VARCHAR(100),
transmission VARCHAR(100),
comments TEXT,
recalled TINYINT(1),
onLot TINYINT(1)
Orders(
ATID CHAR(10) NOT NULL PRIMARY KEY,
customerPhone VARCHAR(20) NOT NULL,
price INT NOT NULL,
datePlaced DATE NOT NULL,
source VARCHAR(255) NOT NULL,
status VARCHAR(255) NOT NULL
FOREIGN KEY (ATID) REFERENCES Cars(ATID),
FOREIGN KEY (customerPhone) REFERNCES
Customers(primaryPhone)
Sold(
ATID CHAR(10) NOT NULL PRIMARY KEY,
customerPhone VARCHAR(20) NOT NULL,
dateSold DATE NOT NULL,
salesman VARCHAR(255) NOT NULL,
finalPrice INT NOT NULL,
FOREIGN KEY (ATID) REFERENCES Cars(ATID),
FOREIGN KEY (customerPhone) REFERNCES
Customers(primaryPhone)
FOREIGN KEY (salesman) REFERNCES Staff (name)
Customers(
primaryPhone VARCHAR(20) NOT NULL PRIMARY KEY,
secondPhone VARCHAR(20),
thirdPhone VARCHAR(20),
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
city VARCHAR(255) NOT NULL,
state VARCHAR(255) NOT NULL,
zip VARCHAR(20) NOT NULL
Staff(
primaryPhone VARCHAR(20) NOT NULL PRIMARY KEY,
secondPhone VARCHAR(20),
thirdPhone VARCHAR(20),
name VARCHAR(255) NOT NULL,
address VARCHAR(255) NOT NULL,
city VARCHAR(255) NOT NULL,
state VARCHAR(255) NOT NUll,
zip VARCHAR(20) NOT NULL,
position VARCHAR(100) NOT NULL