Professional Documents
Culture Documents
Kirk Kosinski
Patrick Cao
OJ Alcaraz
CST 363
GEO Elves
2/18/2020
Project Part 1
After reviewing the project requirements, the GEO Elves have come up with the
database schema listed on the following pages to store the data necessary for the new
confidential online drug store chain being developed by a FAANG company. This database
schema should meet all the requirements given to us except for the following:
● We did not force recently added doctors to have at least one patient, though the design
does connect a prescription in such a way that a patient and a doctor must be connected
in order for a prescription to be listed.
● When a pharmaceutical company is deleted from the database the current schema does
not delete the drugs from the list. We have decided that either we will implement this
functionality with a Cascade Delete or programmatically in the web interface.
-- -----------------------------------------------------
-- Schema drugstore_db
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `drugstore_db` ;
-- -----------------------------------------------------
-- Schema drugstore_db
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `drugstore_db` ;
USE `drugstore_db` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`pharmaceutical_companies`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`pharmaceutical_companies` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`specialties`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`specialties` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`doctors`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`doctors` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`patients`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`patients` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`patdoc_relationship`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`patdoc_relationship` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`prescriptions`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`prescriptions` ;
CREATE TABLE IF NOT EXISTS `drugstore_db`.`prescriptions` (
`ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`quantity` INT NOT NULL,
`drug_id` INT NOT NULL,
`refills_allowed` INT GENERATED ALWAYS AS (),
`patdoc_id` INT NOT NULL,
INDEX `fk_prescriptions_patdoc_idx` (`patdoc_id` ASC) VISIBLE,
PRIMARY KEY (`ID`),
UNIQUE INDEX `uk_drug_patdoc` (`drug_id` ASC, `patdoc_id` ASC) VISIBLE,
CONSTRAINT `fk_prescriptions_patdoc`
FOREIGN KEY (`patdoc_id`)
REFERENCES `drugstore_db`.`patdoc_relationship` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `drugstore_db`.`drugs`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`drugs` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`pharmacies`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`pharmacies` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`pharmacy_drugs`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`pharmacy_drugs` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`supervisors`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`supervisors` ;
-- -----------------------------------------------------
-- Table `drugstore_db`.`pharmacy_contracts`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `drugstore_db`.`pharmacy_contracts` ;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;