SQL File
SQL File
--EdgarS.LeosAlmanza
--MosesGarcia
--CesarSanchez
--CST363FinalProject
--CST363_The_Tech_Guys_Final_Schema
SET@OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS,UNIQUE_CHECKS=0;
SET@OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,
FOREIGN_KEY_CHECKS=0;
SET@OLD_SQL_MODE=@@SQL_MODE,
SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_
ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-------------------------------------------------------
--Schemapharma
-------------------------------------------------------
DROPSCHEMAIFEXISTS`pharma`;
CREATESCHEMAIFNOTEXISTS`pharma`DEFAULTCHARACTERSETutf8;
USE`pharma`;
-------------------------------------------------------
--Table`pharma`.`doctors`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`doctors`(
`ssn`VARCHAR(9)NOTNULL,
`name`VARCHAR(45)NOTNULL,
`specialty`VARCHAR(45)NOTNULL,
`years_of_experience`INTNOTNULL,
PRIMARYKEY(`ssn`),
UNIQUEINDEX`ssn_UNIQUE`(`ssn`ASC)VISIBLE)
ENGINE=InnoDB;
-------------------------------------------------------
--Table`pharma`.`patients`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`patients`(
`ssn`VARCHAR(9)NOTNULL,
`first_name`VARCHAR(45)NOTNULL,
`last_name`VARCHAR(45)NOTNULL,
`age`INTNOTNULL,
`address`VARCHAR(45)NOTNULL,
`doctors_ssn`VARCHAR(9)NOTNULL,
NIQUEINDEX`ssn_UNIQUE`(`ssn`ASC)VISIBLE,
U
PRIMARYKEY(`ssn`),
INDEX`fk_patients_doctors1_idx`(`doctors_ssn`ASC)VISIBLE,
CONSTRAINT`fk_patients_doctors1`
FOREIGNKEY(`doctors_ssn`)
REFERENCES`pharma`.`doctors`(`ssn`)
ONDELETENOACTION
ONUPDATENOACTION)
ENGINE=InnoDB;
-------------------------------------------------------
--Table`pharma`.`pharma_corp`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`pharma_corp`(
`id`INTNOTNULL,
`name`VARCHAR(45)NOTNULL,
`phone_number`VARCHAR(20)NOTNULL,
PRIMARYKEY(`id`))
ENGINE=InnoDB;
-------------------------------------------------------
--Table`pharma`.`drug`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`drug`(
`id`INTNOTNULL,
`trade_name`VARCHAR(45)NOTNULL,
`generic_name`VARCHAR(45)NOTNULL,
`pharma_corp_id`INTNOTNULL,
PRIMARYKEY(`id`),
UNIQUEINDEX`id_UNIQUE`(`id`ASC)VISIBLE,
UNIQUEINDEX`trade_name_UNIQUE`(`trade_name`ASC)VISIBLE,
INDEX`fk_drug_pharma_corp1_idx`(`pharma_corp_id`ASC)VISIBLE,
CONSTRAINT`fk_drug_pharma_corp1`
FOREIGNKEY(`pharma_corp_id`)
REFERENCES`pharma`.`pharma_corp`(`id`)
ONDELETENOACTION
ONUPDATENOACTION)
ENGINE=InnoDB;
-------------------------------------------------------
--Table`pharma`.`pharmacy`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`pharmacy`(
`id`INTNOTNULLAUTO_INCREMENT,
`name`VARCHAR(45)NOTNULL,
`address`VARCHAR(45)NOTNULL,
`phone_number`VARCHAR(20)NOTNULL,
PRIMARYKEY(`id`),
UNIQUEINDEX`id_UNIQUE`(`id`ASC)VISIBLE)
ENGINE=InnoDB;
-------------------------------------------------------
--Table`pharma`.`prescription`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`prescription`(
`id`INTNOTNULLAUTO_INCREMENT,
`prescribed_date`DATENOTNULL,
`quantity`INTNOTNULL,
`number_of_refills`INTNOTNULLDEFAULT0,
`drug_id`INTNOTNULL,
`doctors_ssn`VARCHAR(9)NOTNULL,
`patients_ssn`VARCHAR(9)NOTNULL,
`pharmacy_id`INT NULL,
PRIMARYKEY(`id`),
INDEX`fk_prescribed_drugs_drug1_idx`(`drug_id`ASC)VISIBLE,
INDEX`fk_prescription_doctors1_idx`(`doctors_ssn`ASC)VISIBLE,
INDEX`fk_prescription_patients1_idx`(`patients_ssn`ASC)VISIBLE,
INDEX`fk_prescription_pharmacy1_idx`(`pharmacy_id`ASC)VISIBLE,
CONSTRAINT`fk_prescribed_drugs_drug1`
FOREIGNKEY(`drug_id`)
REFERENCES`pharma`.`drug`(`id`)
ONDELETENOACTION
ONUPDATENOACTION,
CONSTRAINT`fk_prescription_doctors1`
FOREIGNKEY(`doctors_ssn`)
REFERENCES`pharma`.`doctors`(`ssn`)
ONDELETENOACTION
ONUPDATENOACTION,
CONSTRAINT`fk_prescription_patients1`
FOREIGNKEY(`patients_ssn`)
REFERENCES`pharma`.`patients`(`ssn`)
ONDELETENOACTION
ONUPDATENOACTION,
CONSTRAINT`fk_prescription_pharmacy1`
OREIGNKEY(`pharmacy_id`)
F
REFERENCES`pharma`.`pharmacy`(`id`)
ONDELETENOACTION
ONUPDATENOACTION)
ENGINE=InnoDB;
-------------------------------------------------------
--Table`pharma`.`contracts`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`contracts`(
`id`INTNOTNULL,
`start_date`DATETIMENULL,
`end_date`DATETIMENULL,
`text`LONGTEXTNULL,
`supervisor`VARCHAR(45)NOTNULL,
`pharmacy_id`INTNOTNULL,
`supervisor_id`INTNOTNULL,
PRIMARYKEY(`id`),
INDEX`fk_contracts_pharmacy1_idx`(`pharmacy_id`ASC)VISIBLE,
INDEX`fk_contracts_pharma_corp1_idx`(`supervisor_id`ASC)VISIBLE,
CONSTRAINT`fk_contracts_pharmacy1`
FOREIGNKEY(`pharmacy_id`)
REFERENCES`pharma`.`pharmacy`(`id`)
ONDELETENOACTION
ONUPDATENOACTION,
CONSTRAINT`fk_contracts_pharma_corp1`
FOREIGNKEY(`supervisor_id`)
REFERENCES`pharma`.`pharma_corp`(`id`)
ONDELETENOACTION
ONUPDATENOACTION)
ENGINE=InnoDB;
-------------------------------------------------------
--Table`pharma`.`pharmacy_has_drug`
-------------------------------------------------------
CREATETABLEIFNOTEXISTS`pharma`.`pharmacy_has_drug`(
`pharmacy_id`INTNOTNULL,
`drug_id`INTNOTNULL,
`price`DECIMAL(6,2)NULL,
PRIMARYKEY(`pharmacy_id`,`drug_id`),
INDEX`fk_pharmacy_has_drug_drug1_idx`(`drug_id`ASC)VISIBLE,
INDEX`fk_pharmacy_has_drug_pharmacy1_idx`(`pharmacy_id`ASC)VISIBLE,
CONSTRAINT`fk_pharmacy_has_drug_pharmacy1`
FOREIGNKEY(`pharmacy_id`)
REFERENCES`pharma`.`pharmacy`(`id`)
ONDELETENOACTION
ONUPDATENOACTION,
CONSTRAINT`fk_pharmacy_has_drug_drug1`
FOREIGNKEY(`drug_id`)
REFERENCES`pharma`.`drug`(`id`)
ONDELETENOACTION
ONUPDATENOACTION)
ENGINE=InnoDB;
/*************************************PatientData********************************/
INSERTINTOpatientsVALUES('123456789','Ella-Grace','Bowes','23','1922 Bagwell
Avenue','987321654');
INSERTINTOpatientsVALUES('234567891','Tommy','Calhoun','45','3968 SugarCamp
Road','895623741');
INSERTINTOpatientsVALUES('345678912','Jordan-Lee','Tierney','12','4801 DukeLane',
'159743628');
INSERTINTOpatientsVALUES('456789123','Nial','Mckeown','45','4537 SunnyDayDrive',
'961234785');
INSERTINTOpatientsVALUES('567891234','Nikhil','Legge','78','3268 WildwoodStreet',
'789654123');
INSERTINTOpatientsVALUES('678912345','Shayaan','Clayton','65','3370 FrankAvenue',
'927183465');
INSERTINTOpatientsVALUES('789123456','Renesmae','Field','32','1243 BriarhillLane',
'157849632');
INSERTINTOpatientsVALUES('891234567','Catriona','Worthington','94','3515 ShadyPines
Drive','987415263');
INSERTINTOpatientsVALUES('912345678','Eben','Salter','23','4194 CrestviewManor',
'349781526');
INSERTINTOpatientsVALUES('987654321','Enya','Mccoy','45','2366 EarnhardtDrive',
'528741693');
INSERTINTOpatientsVALUES('876543219','Fariha','George','18','1101 HappyHollow
Road','987321654');
INSERTINTOpatientsVALUES('765432198','Catrin','Olson','45','4343 ValleyDrive',
'895623741');
INSERTINTOpatientsVALUES('654321987','Padraig','Rollins','26','4748 SteveHuntRoad',
'159743628');
INSERTINTOpatientsVALUES('543219876','Christiana','Bryan','35','1618 CharackRoad',
'961234785');
INSERTINTOpatientsVALUES('432198765','Freddie','Robin','25','2934 FlorenceStreet',
'789654123');
INSERTINTOpatientsVALUES('321654987','Bethan','Willis','46','3863 PointStreet',
'927183465');
INSERTINTOpatientsVALUES('216549873','Shaquille','Mckenna','12','4569 RitterAvenue',
'157849632');
INSERTINTOpatientsVALUES('198765432','Kelvin','Parker','34','757 ElkCityRoad',
'987415263');
INSERTINTOpatientsVALUES('321987654','Rebecca','Barrow','39','2544 DoeMeadow
Drive','349781526');
INSERTINTOpatientsVALUES('654987321','Gilbert','Connelly','25','3184 UniversityHill
Road','528741693');
/*************************************DoctorData********************************/
INSERTINTOdoctorsVALUES('987321654','Parsons','DERMATOLOGY','4');
INSERTINTOdoctorsVALUES('895623741','Hobbs','NEUROLOGY','8');
INSERTINTOdoctorsVALUES('159743628','Driscoll','OPHTHALMOLOGY','5');
INSERTINTOdoctorsVALUES('961234785','Mcneill','PATHOLOGY','2');
INSERTINTOdoctorsVALUES('789654123','Harding','PEDIATRICS','8');
INSERTINTOdoctorsVALUES('927183465','Simon','SURGERY','7');
INSERTINTOdoctorsVALUES('157849632','Melendez','UROLOGY','5');
INSERTINTOdoctorsVALUES('987415263','Marsh','ONCOLOGY','4');
INSERTINTOdoctorsVALUES('349781526','Paine','OPHTHALMOLOGY','6');
INSERTINTOdoctorsVALUES('528741693','Brien','PATHOLOGY','8');
/*************************************PharmacyCorporationsData********************************/
INSERTINTOpharma_corpVALUES('1','BigPharma','123-456-7879');
INSERTINTOpharma_corpVALUES('2','LittlePharma','234-567-8901');
INSERTINTOpharma_corpVALUES('3','MediumPharma','345-678-9012');
INSERTINTOpharma_corpVALUES('4','CheapPharma','456-789-0123');
INSERTINTOpharma_corpVALUES('5','ExpensivePharma','567-890-1234');
/*************************************DrugData********************************/
INSERTINTOdrugVALUES('1','Headacheaway','alendronatetablet','5');
INSERTINTOdrugVALUES('2','Stomachacheaway','acyclovircapsule','4');
INSERTINTOdrugVALUES('3','Shoulderacheraway','acyclovirtablet','3');
INSERTINTOdrugVALUES('4','Handacheaway','albuterolinhalationsolution','4');
INSERTINTOdrugVALUES('5','Feetacheaway','albuterolsulfate','2');
INSERTINTOdrugVALUES('6','Coughaway','alclometasonedipropionatecream','1');
INSERTINTOdrugVALUES('7','Feveraway','alfuzosinhcl','3');
INSERTINTOdrugVALUES('8','Painaway','alitretinoin','2');
INSERTINTOdrugVALUES('9','Bruiseaway','allopurinoltablet','4');
INSERTINTOdrugVALUES('10','Sleepaway','alprazolam','2');
/*************************************PharmacyData********************************/
INSERTINTOpharmacyVALUES('1','CVS','1327FenleyAve','678-901-2345');
INSERTINTOpharmacyVALUES('2','DrugMart','10274thSt','789-012-3456');
INSERTINTOpharmacyVALUES('3','RiteAid','190CouchRd','890-123-4567');
INSERTINTOpharmacyVALUES('4','Walgreens','1130NWalnutSt','012-345-5678');
INSERTINTOpharmacyVALUES('5','CareFirst','2255WilsonSt','098-765-4321');
INSERTINTOpharmacyVALUES('6','Caremark','151EarlsPonderosaLn','987-654-3210');
INSERTINTOpharmacyVALUES('7','Carepoint','57SmokeTreeLn','876-543-2109');
/*************************************PharmacyHasDrugData********************************/
INSERTINTOpharmacy_has_drugVALUES('1','1','10.67');
INSERTINTOpharmacy_has_drugVALUES('1','2','28.76');
INSERTINTOpharmacy_has_drugVALUES('1','3','35.84');
INSERTINTOpharmacy_has_drugVALUES('1','4','49.63');
INSERTINTOpharmacy_has_drugVALUES('1','5','33.8');
INSERTINTOpharmacy_has_drugVALUES('1','6','25.58');
INSERTINTOpharmacy_has_drugVALUES('1','7','12.39');
INSERTINTOpharmacy_has_drugVALUES('1','8','18.39');
INSERTINTOpharmacy_has_drugVALUES('1','9','18.64');
INSERTINTOpharmacy_has_drugVALUES('1','10','4.85');
INSERTINTOpharmacy_has_drugVALUES('2','1','40.52');
INSERTINTOpharmacy_has_drugVALUES('2','2','20.35');
INSERTINTOpharmacy_has_drugVALUES('2','3','10.82');
INSERTINTOpharmacy_has_drugVALUES('2','4','29.09');
INSERTINTOpharmacy_has_drugVALUES('2','5','39.84');
INSERTINTOpharmacy_has_drugVALUES('2','6','34.77');
INSERTINTOpharmacy_has_drugVALUES('3','7','16.74');
INSERTINTOpharmacy_has_drugVALUES('3','8','49.5');
INSERTINTOpharmacy_has_drugVALUES('3','9','30.48');
INSERTINTOpharmacy_has_drugVALUES('3','10','19.77');
INSERTINTOpharmacy_has_drugVALUES('4','4','22.1');
INSERTINTOpharmacy_has_drugVALUES('4','5','5.12');
INSERTINTOpharmacy_has_drugVALUES('4','6','30.75');
INSERTINTOpharmacy_has_drugVALUES('4','9','19.99');
INSERTINTOpharmacy_has_drugVALUES('5','7','37.18');
INSERTINTOpharmacy_has_drugVALUES('5','8','6.62');
INSERTINTOpharmacy_has_drugVALUES('5','9','30.73');
INSERTINTOpharmacy_has_drugVALUES('5','10','9.77');
INSERTINTOpharmacy_has_drugVALUES('6','1','34.7');
INSERTINTOpharmacy_has_drugVALUES('6','2','5.01');
INSERTINTOpharmacy_has_drugVALUES('6','9','10.85');
INSERTINTOpharmacy_has_drugVALUES('6','8','30.56');
INSERTINTOpharmacy_has_drugVALUES('6','10','42.11');
INSERTINTOpharmacy_has_drugVALUES('7','3','17.58');
INSERTINTOpharmacy_has_drugVALUES('7','5','24.34');
INSERTINTOpharmacy_has_drugVALUES('7','6','28.83');
INSERTINTOpharmacy_has_drugVALUES('7','7','9.35');
INSERTINTOpharmacy_has_drugVALUES('7','8','36.18');
INSERTINTOpharmacy_has_drugVALUES('7','9','30.55');
INSERTINTOpharmacy_has_drugVALUES('7','10','42.84');
SETSQL_MODE=@OLD_SQL_MODE;
SETFOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SETUNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;