Professional Documents
Culture Documents
Team 2 B
Team 2 B
-- -----------------------------------------------------
-- Schema ProjectPharmacy
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema ProjectPharmacy
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `ProjectPharmacy` DEFAULT CHARACTER SET utf8 ;
USE `ProjectPharmacy` ;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Doctor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Doctor` (
`idDoctor` INT NOT NULL AUTO_INCREMENT,
`doctorFirstName` VARCHAR(45) NOT NULL,
`doctorLastName` VARCHAR(45) NOT NULL,
`specialty` VARCHAR(45) NOT NULL,
`practice_since` INT NOT NULL,
`doctorSSN` VARCHAR(11) NOT NULL,
PRIMARY KEY (`idDoctor`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Patient`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Patient` (
`idPatient` INT NOT NULL AUTO_INCREMENT,
`patientFirstName` VARCHAR(45) NOT NULL,
`patientLastName` VARCHAR(45) NOT NULL,
`birthdate` DATE NOT NULL,
`patientSSN` VARCHAR(11) NOT NULL,
`patientStreet` VARCHAR(50) NOT NULL,
`patientCity` VARCHAR(25) NOT NULL,
`patientState` VARCHAR(2) NOT NULL,
`patientZip` VARCHAR(25) NOT NULL,
`idPrimaryDoctor` INT NOT NULL,
PRIMARY KEY (`idPatient`),
INDEX `fk_Patient_Doctor1_idx` (`idPrimaryDoctor` ASC) VISIBLE,
CONSTRAINT `fk_Patient_Doctor1`
FOREIGN KEY (`idPrimaryDoctor`)
REFERENCES `ProjectPharmacy`.`Doctor` (`idDoctor`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Pharmacy`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Pharmacy` (
`idPharmacy` INT NOT NULL AUTO_INCREMENT,
`pharmName` VARCHAR(45) NOT NULL,
`pharmAddress` VARCHAR(100) NOT NULL,
`pharmPhoneNumber` VARCHAR(13) NOT NULL,
PRIMARY KEY (`idPharmacy`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Drug`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Drug` (
`idDrug` INT(11) NOT NULL,
`tradeName` VARCHAR(100) NOT NULL,
`genericFormula` VARCHAR(200) NOT NULL,
PRIMARY KEY (`idDrug`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Prescription`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Prescription` (
`idPrescription` INT NOT NULL AUTO_INCREMENT,
`quantity` INT NOT NULL,
`prescriptionDate` DATE NOT NULL,
`dateFilled` DATE NULL,
`idDoctor` INT NOT NULL,
`idPatient` INT NOT NULL,
`idPharmacy` INT NULL,
`idDrug` INT NOT NULL,
PRIMARY KEY (`idPrescription`, `idPatient`, `idDrug`),
INDEX `fk_Prescription_Doctor1_idx` (`idDoctor` ASC) VISIBLE,
INDEX `fk_Prescription_Patient1_idx` (`idPatient` ASC) VISIBLE,
INDEX `fk_Prescription_Pharmacy1_idx` (`idPharmacy` ASC) VISIBLE,
INDEX `fk_Prescription_Drug1_idx` (`idDrug` ASC) VISIBLE,
CONSTRAINT `fk_Prescription_Doctor1`
FOREIGN KEY (`idDoctor`)
REFERENCES `ProjectPharmacy`.`Doctor` (`idDoctor`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Prescription_Patient1`
FOREIGN KEY (`idPatient`)
REFERENCES `ProjectPharmacy`.`Patient` (`idPatient`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Prescription_Pharmacy1`
FOREIGN KEY (`idPharmacy`)
REFERENCES `ProjectPharmacy`.`Pharmacy` (`idPharmacy`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Prescription_Drug1`
FOREIGN KEY (`idDrug`)
REFERENCES `ProjectPharmacy`.`Drug` (`idDrug`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`PharmaCompany`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`PharmaCompany` (
`idPharmaCompany` INT NOT NULL AUTO_INCREMENT,
`pharmaCompanyName` VARCHAR(45) NOT NULL,
`pharmaCompanyPhone` VARCHAR(13) NOT NULL,
PRIMARY KEY (`idPharmaCompany`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Supervisor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Supervisor` (
`idSupervisor` INT NOT NULL AUTO_INCREMENT,
`supervisorFirstName` VARCHAR(45) NOT NULL,
`supervisorLastName` VARCHAR(45) NOT NULL,
`supervisorPhone` VARCHAR(13) NOT NULL,
PRIMARY KEY (`idSupervisor`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Contract`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Contract` (
`idContract` INT NOT NULL AUTO_INCREMENT,
`startDate` DATE NOT NULL,
`endDate` DATE NOT NULL,
`contractText` VARCHAR(45) NOT NULL,
`idPharmaCompany` INT NOT NULL,
`idSupervisor` INT NOT NULL,
`idPharmacy` INT NOT NULL,
PRIMARY KEY (`idContract`),
INDEX `fk_Contract_PharmaCompany1_idx` (`idPharmaCompany` ASC) VISIBLE,
INDEX `fk_Contract_Supervisor1_idx` (`idSupervisor` ASC) VISIBLE,
INDEX `fk_Contract_Pharmacy1_idx` (`idPharmacy` ASC) VISIBLE,
CONSTRAINT `fk_Contract_PharmaCompany1`
FOREIGN KEY (`idPharmaCompany`)
REFERENCES `ProjectPharmacy`.`PharmaCompany` (`idPharmaCompany`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Contract_Supervisor1`
FOREIGN KEY (`idSupervisor`)
REFERENCES `ProjectPharmacy`.`Supervisor` (`idSupervisor`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Contract_Pharmacy1`
FOREIGN KEY (`idPharmacy`)
REFERENCES `ProjectPharmacy`.`Pharmacy` (`idPharmacy`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Sells`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Sells` (
`idDrug` INT NOT NULL,
`idPharmacy` INT NOT NULL,
`price` DECIMAL(7,2) NOT NULL,
PRIMARY KEY (`idDrug`, `idPharmacy`),
INDEX `fk_Drug_has_Pharmacy_Pharmacy1_idx` (`idPharmacy` ASC) VISIBLE,
INDEX `fk_Drug_has_Pharmacy_Drug1_idx` (`idDrug` ASC) VISIBLE,
CONSTRAINT `fk_Drug_has_Pharmacy_Drug1`
FOREIGN KEY (`idDrug`)
REFERENCES `ProjectPharmacy`.`Drug` (`idDrug`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Drug_has_Pharmacy_Pharmacy1`
FOREIGN KEY (`idPharmacy`)
REFERENCES `ProjectPharmacy`.`Pharmacy` (`idPharmacy`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `ProjectPharmacy`.`Drug_has_PharmaCompany`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `ProjectPharmacy`.`Drug_has_PharmaCompany` (
`Drug_idDrug` INT(11) NOT NULL,
`PharmaCompany_idPharmaCompany` INT NOT NULL,
PRIMARY KEY (`Drug_idDrug`, `PharmaCompany_idPharmaCompany`),
INDEX `fk_Drug_has_PharmaCompany_PharmaCompany1_idx`
(`PharmaCompany_idPharmaCompany` ASC) VISIBLE,
INDEX `fk_Drug_has_PharmaCompany_Drug1_idx` (`Drug_idDrug` ASC) VISIBLE,
CONSTRAINT `fk_Drug_has_PharmaCompany_Drug1`
FOREIGN KEY (`Drug_idDrug`)
REFERENCES `ProjectPharmacy`.`Drug` (`idDrug`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Drug_has_PharmaCompany_PharmaCompany1`
FOREIGN KEY (`PharmaCompany_idPharmaCompany`)
REFERENCES `ProjectPharmacy`.`PharmaCompany` (`idPharmaCompany`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
--
-- Table structure for table `drug`
--
-- DROP TABLE IF EXISTS `drug`;
-- CREATE TABLE `drug` (
-- `idDrug` int(11) NOT NULL,
-- `tradeName` varchar(100) NOT NULL,
-- `genericformula` varchar(200) NOT NULL,
-- PRIMARY KEY (`idDrug`)
-- );
INSERT INTO `drug` VALUES
(1,'Tylenol with Codeine','acetaminophen and codeine'),
(2,'Proair Proventil','albuterol aerosol'),
(3,'Accuneb','albuterol HFA'),
(4,'Fosamax','alendronate'),
(5,'Zyloprim','allopurinol'),
(6,'Xanax','alprazolam'),
(7,'Elavil','amitriptyline'),
(8,'Augmentin','amoxicillin and clavulanate K+'),
(9,'Amoxil','amoxicillin'),
(10,'Adderall XR','amphetamine and dextroamphetamine XR'),
(11,'Tenormin','atenolol'),
(12,'Lipitor','atorvastatin'),
(13,'Zithromax','azithromycin'),
(14,'Lotrel','benazepril and amlodipine'),
(15,'Soma','carisoprodol'),
(16,'Coreg','carvedilol'),
(17,'Omnicef','cefdinir'),
(18,'Celebrex','celecoxib'),
(19,'Keflex','cephalexin'),
(20,'Cipro','ciprofloxacin'),
(21,'Celexa','citalopram'),
(22,'Klonopin','clonazepam'),
(23,'Catapres','clonidine HCl'),
(24,'Plavix','clopidogrel'),
(25,'Premarin','conjugated estrogens'),
(26,'Flexeril','cyclobenzaprine'),
(27,'Valium','diazepam'),
(28,'Voltaren','diclofenac sodium'),
(29,'Yaz','drospirenone and ethinyl estradiol'),
(30,'Cymbalta','Duloxetine'),
(31,'Vibramycin','doxycycline hyclate'),
(32,'Vasotec','enalapril'),
(33,'Lexapro','escitalopram'),
(34,'Nexium','esomeprazole'),
(35,'Zetia','ezetimibe'),
(36,'Tricor','fenofibrate'),
(37,'Allegra','fexofenadine'),
(38,'Diflucan','fluconozole'),
(39,'Prozac','fluoxetine HCl'),
(40,'Advair','fluticasone and salmeterol inhaler'),
(41,'Flonase','fluticasone nasal spray'),
(42,'Folic Acid','folic acid'),
(43,'Lasix','furosemide'),
(44,'Neurontin','gabapentin'),
(45,'Amaryl','glimepiride'),
(46,'Diabeta','glyburide'),
(47,'Glucotrol','glipizide'),
(48,'Microzide','hydrochlorothiazide'),
(49,'Lortab','hydrocodone and acetaminophen'),
(50,'Motrin','ibuprophen'),
(51,'Lantus','insulin glargine'),
(52,'Imdur','isosorbide mononitrate'),
(53,'Prevacid','lansoprazole'),
(54,'Levaquin','levofloxacin'),
(55,'Levoxl','levothyroxine sodium'),
(56,'Zestoretic','lisinopril and hydrochlorothiazide'),
(57,'Prinivil','lisinopril'),
(58,'Ativan','lorazepam'),
(59,'Cozaar','losartan'),
(60,'Mevacor','lovastatin'),
(61,'Mobic','meloxicam'),
(62,'Glucophage','metformin HCl'),
(63,'Medrol','methylprednisone'),
(64,'Toprol','metoprolol succinate XL'),
(65,'Lopressor','metoprolol tartrate'),
(66,'Nasonex','mometasone'),
(67,'Singulair','montelukast'),
(68,'Naprosyn','naproxen'),
(69,'Prilosec','omeprazole'),
(70,'Percocet','oxycodone and acetaminophen'),
(71,'Protonix','pantoprazole'),
(72,'Paxil','paroxetine'),
(73,'Actos','pioglitazone'),
(74,'Klor-Con','potassium Chloride'),
(75,'Pravachol','pravastatin'),
(76,'Deltasone','prednisone'),
(77,'Lyrica','pregabalin'),
(78,'Phenergan','promethazine'),
(79,'Seroquel','quetiapine'),
(80,'Zantac','ranitidine'),
(81,'Crestor','rosuvastatin'),
(82,'Zoloft','sertraline HCl'),
(83,'Viagra','sildenafil HCl'),
(84,'Vytorin','simvastatin and ezetimibe'),
(85,'Zocor','simvastatin'),
(86,'Aldactone','spironolactone'),
(87,'Bactrim DS','sulfamethoxazole and trimethoprim DS'),
(88,'Flomax','tamsulosin'),
(89,'Restoril','temezepam'),
(90,'Topamax','topiramate'),
(91,'Ultram','tramadol'),
(92,'Aristocort','triamcinolone Ace topical'),
(93,'Desyrel','trazodone HCl'),
(94,'Dyazide','triamterene and hydrochlorothiazide'),
(95,'Valtrex','valaciclovir'),
(96,'Diovan','valsartan'),
(97,'Effexor XR','venlafaxine XR'),
(98,'Calan SR','verapamil SR'),
(99,'Ambien','zolpidem');
--
-- Table structure for table `pharmacy`
--
-- DROP TABLE IF EXISTS `pharmacy`;
-- CREATE TABLE `pharmacy` (
-- `idPharmacy` INT NOT NULL AUTO_INCREMENT,
-- `pharmName` VARCHAR(45) NOT NULL,
-- `pharmAddress` VARCHAR(100) NOT NULL,
-- `pharmPhoneNumber` VARCHAR(13) NOT NULL,
-- PRIMARY KEY (`idPharmacy`)
-- );
-- -- #5 Display patientZip as the zip code where the highest number of patients
reside as well
-- -- as the corresponding number of patients as ‘highestNumOfPatients’.
SELECT patientZip, MAX(patients) AS 'highestNumOfPatients'
FROM (SELECT patientZip, COUNT(p.idPatient) AS 'patients'
FROM Patient p GROUP BY patientZip) AS zipCount;
-- -- This query can be used by public health and pharmacy professionals to
understand
-- -- which areas have the highest need and therefore invest more resources in
those areas.