0% found this document useful (0 votes)
27 views14 pages

cst363 Schema

Uploaded by

api-635181702
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views14 pages

cst363 Schema

Uploaded by

api-635181702
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

DROP DATABASE IF EXISTS `cst363`;

CREATE DATABASE IF NOT EXISTS `cst363` /*!40100 DEFAULT CHARACTER SET utf8mb3
*/ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `cst363`;
-- MySQL dump 10.13 Distrib 8.0.31, for Win64 (x86_64)
--
-- Host: localhost Database: cst363
-- ------------------------------------------------------
-- Server version 8.0.31

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;


/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,
FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE,
SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `company`
--

DROP TABLE IF EXISTS `company`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `company` (
`companyId` int NOT NULL AUTO_INCREMENT,
`companyName` varchar(45) NOT NULL,
`companyPhone` varchar(17) NOT NULL,
PRIMARY KEY (`companyId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `company`
--

LOCK TABLES `company` WRITE;


/*!40000 ALTER TABLE `company` DISABLE KEYS */;
/*!40000 ALTER TABLE `company` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `companymakesdrug`
--

DROP TABLE IF EXISTS `companymakesdrug`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `companymakesdrug` (
`companyId` int NOT NULL,
`drugId` int NOT NULL,
PRIMARY KEY (`companyId`,`drugId`),
KEY `fk_drugToCompany_drug1_idx` (`drugId`),
KEY `fk_drugToCompany_company1_idx` (`companyId`),
CONSTRAINT `fk_drugToCompany_company1` FOREIGN KEY (`companyId`) REFERENCES
`company` (`companyId`),
CONSTRAINT `fk_drugToCompany_drug1` FOREIGN KEY (`drugId`) REFERENCES `drug`
(`drugId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `companymakesdrug`
--

LOCK TABLES `companymakesdrug` WRITE;


/*!40000 ALTER TABLE `companymakesdrug` DISABLE KEYS */;
/*!40000 ALTER TABLE `companymakesdrug` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `contract`
--

DROP TABLE IF EXISTS `contract`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `contract` (
`contractId` int NOT NULL AUTO_INCREMENT,
`pharmacyId` int NOT NULL,
`companyId` int NOT NULL,
`startDate` date NOT NULL,
`endDate` date NOT NULL,
`supervisorName` varchar(45) NOT NULL,
`contents` varchar(200) NOT NULL,
PRIMARY KEY (`contractId`),
KEY `fk_contract_pharmacy1_idx` (`pharmacyId`),
KEY `fk_contract_company1_idx` (`companyId`),
CONSTRAINT `fk_contract_company1` FOREIGN KEY (`companyId`) REFERENCES
`company` (`companyId`),
CONSTRAINT `fk_contract_pharmacy1` FOREIGN KEY (`pharmacyId`) REFERENCES
`pharmacy` (`pharmacyId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `contract`
--

LOCK TABLES `contract` WRITE;


/*!40000 ALTER TABLE `contract` DISABLE KEYS */;
/*!40000 ALTER TABLE `contract` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `doctor`
--

DROP TABLE IF EXISTS `doctor`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `doctor` (
`doctorId` int NOT NULL AUTO_INCREMENT,
`doctorSSN` char(9) NOT NULL,
`doctorFirstName` varchar(45) NOT NULL,
`doctorLastName` varchar(45) NOT NULL,
`specialty` varchar(45) NOT NULL,
`practiceSinceYear` int NOT NULL,
PRIMARY KEY (`doctorId`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `doctor`
--
LOCK TABLES `doctor` WRITE;
/*!40000 ALTER TABLE `doctor` DISABLE KEYS */;
INSERT INTO `doctor` VALUES (1,'839935448','Liam','Johnson','Family
Medicine',2019),(2,'464536858','Olivia','Williams','Pediatrics',2004),(3,'792675159','Noah','Jones'
,'Orthpedics',2012),(4,'803870099','Ava','Brown','Dermatology',2002),(5,'294934823','Isabella','D
avis','Cardiology',2005),(6,'622605140','Sophia','Garcia','Gynecology',2002),(7,'636196541','Jac
kson','Rodriguez','Gastroenterology',2005),(8,'318095042','Mia','Martinez','Psychiatry',2001),(9,'
202398369','Aiden','Hernandez','Oncology',2007),(10,'211962163','Charlotte','Lopez','Internal
Medicine',2019);
/*!40000 ALTER TABLE `doctor` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `drug`
--

DROP TABLE IF EXISTS `drug`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `drug` (
`drugId` int NOT NULL AUTO_INCREMENT,
`tradeName` varchar(45) DEFAULT NULL,
`genericName` varchar(45) NOT NULL,
PRIMARY KEY (`drugId`),
UNIQUE KEY `tradeName_UNIQUE` (`tradeName`)
) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `drug`
--

LOCK TABLES `drug` WRITE;


/*!40000 ALTER TABLE `drug` DISABLE KEYS */;
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','am
itriptyline'),(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,'Celeb
rex','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,'Diabet
a','glyburide'),(47,'Glucotrol','glipizide'),(48,'Microzide','hydrochlorothiazide'),(49,'Lortab','hydroco
done and acetaminophen'),(50,'Motrin','ibuprophen'),(51,'Lantus','insulin
glargine'),(52,'Imdur','isosorbide
mononitrate'),(53,'Prevacid','lansoprazole'),(54,'Levaquin','levofloxacin'),(55,'Levoxl','levothyroxin
e 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'),(6
9,'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','ros
uvastatin'),(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,'Ultra
m','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');
/*!40000 ALTER TABLE `drug` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `fill`
--

DROP TABLE IF EXISTS `fill`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `fill` (
`fillId` int NOT NULL AUTO_INCREMENT,
`rxNum` int NOT NULL,
`pharmacyId` int NOT NULL,
`fillDrugId` int NOT NULL,
`fillGenericCompanyId` int DEFAULT NULL,
`fillDate` date NOT NULL,
PRIMARY KEY (`fillId`),
KEY `fk_fill_prescription1_idx` (`rxNum`),
KEY `fk_fill_pharmacy1_idx` (`pharmacyId`),
KEY `fk_fill_drug1_idx` (`fillDrugId`),
KEY `fk_fill_company1_idx` (`fillGenericCompanyId`),
CONSTRAINT `fk_fill_company1` FOREIGN KEY (`fillGenericCompanyId`) REFERENCES
`company` (`companyId`),
CONSTRAINT `fk_fill_drug1` FOREIGN KEY (`fillDrugId`) REFERENCES `drug` (`drugId`),
CONSTRAINT `fk_fill_pharmacy1` FOREIGN KEY (`pharmacyId`) REFERENCES `pharmacy`
(`pharmacyId`),
CONSTRAINT `fk_fill_prescription1` FOREIGN KEY (`rxNum`) REFERENCES `prescription`
(`rxNum`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `fill`
--

LOCK TABLES `fill` WRITE;


/*!40000 ALTER TABLE `fill` DISABLE KEYS */;
/*!40000 ALTER TABLE `fill` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `patient`
--

DROP TABLE IF EXISTS `patient`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `patient` (
`patientId` int NOT NULL AUTO_INCREMENT,
`primaryDoctorId` int NOT NULL,
`patientSSN` char(9) NOT NULL,
`patientFirstName` varchar(45) NOT NULL,
`patientLastName` varchar(45) NOT NULL,
`patientBirthdate` date NOT NULL,
`patientState` varchar(45) NOT NULL,
`patientZip` varchar(9) NOT NULL,
`patientCity` varchar(45) NOT NULL,
`patientStreet` varchar(45) NOT NULL,
PRIMARY KEY (`patientId`),
KEY `fk_patient_doctor1_idx` (`primaryDoctorId`),
CONSTRAINT `fk_patient_doctor1` FOREIGN KEY (`primaryDoctorId`) REFERENCES
`doctor` (`doctorId`)
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `patient`
--

LOCK TABLES `patient` WRITE;


/*!40000 ALTER TABLE `patient` DISABLE KEYS */;
INSERT INTO `patient` VALUES
(1,5,'622434602','Liam','Johnson','1940-07-05','Alaska','60746','Bristol','Blessed
Rd'),(2,5,'461323153','Olivia','Williams','2000-01-03','Arizona','83299','Chandler','Celestial
Ave'),(3,9,'686936540','Noah','Jones','1949-05-03','Arkansas','15593','Dover','Dream
Blvd'),(4,3,'823614085','Ava','Brown','1947-10-29','California','30475','Everett','Elysian
St'),(5,8,'193588651','Isabella','Davis','1956-12-08','Colorado','85520','Franklin','Fantasy
Rd'),(6,8,'570308450','Sophia','Garcia','1957-03-10','Connecticut','32987','Glendale','Gates
St'),(7,8,'162889461','Jackson','Rodriguez','2013-11-13','Delaware','45961','Harrison','Haven
Ave'),(8,3,'490657422','Mia','Martinez','1956-03-25','Florida','15731','Irvine','Infinite
Way'),(9,3,'520278684','Aiden','Hernandez','1974-10-26','Georgia','56867','Jefferson','Jewel
Rd'),(10,4,'730822969','Charlotte','Lopez','1960-09-15','Hawaii','87275','Kenton','Kismet
St'),(11,1,'153610697','Harper','Gonzalez','1979-03-02','Idaho','78798','Lancaster','Lunar
Ave'),(12,9,'332714992','Elijah','Wilson','1962-04-05','Illinois','79445','Mesa','Majestic
St'),(13,7,'583193005','Amelia','Anderson','1988-05-05','Indiana','49598','Newport','Nirvana
Rd'),(14,5,'216334880','Lucas','Thomas','1950-12-13','Iowa','80405','Oakland','Oracle
Way'),(15,3,'732600760','Evelyn','Jackson','1989-10-09','Kansas','39795','Portsmouth','Pleasant
St'),(16,9,'458049628','Mason','White','1987-05-07','Kentucky','37260','Quincy','Quiet
Ave'),(17,9,'548713531','Abigail','Harris','1948-05-25','Louisiana','49876','Raleigh','Radiant
St'),(18,8,'363403194','William','Martin','1942-03-03','Maine','52087','Savannah','Sunset
Blvd'),(19,1,'126156927','Scarlett','Thompson','1996-09-11','Maryland','97458','Tacoma','Arcane
St'),(20,4,'703612867','Emma','Smith','1945-10-28','Massachusetts','94732','Union','Blessed
Rd'),(21,10,'376075422','Liam','Johnson','1994-11-08','Michigan','65029','Ventura','Celestial
Ave'),(22,2,'799031051','Olivia','Williams','1994-01-16','Minnesota','28179','Waltham','Dream
Blvd'),(23,3,'879841105','Noah','Jones','1986-03-02','Mississippi','97294','Xenia','Elysian
St'),(24,9,'462834163','Ava','Brown','1997-08-06','Missouri','53613','Yuma','Fantasy
Rd'),(25,6,'839718790','Isabella','Davis','1992-08-26','Montana','36711','Zion','Gates
St'),(26,2,'391713727','Sophia','Garcia','2021-01-14','Nebraska','93803','Aurora','Haven
Ave'),(27,5,'824365615','Jackson','Rodriguez','2004-06-09','Nevada','16505','Bristol','Infinite
Way'),(28,1,'350330807','Mia','Martinez','1946-10-31','New Hampshire','41828','Chandler','Jewel
Rd'),(29,5,'203801823','Aiden','Hernandez','2002-05-01','New Jersey','62941','Dover','Kismet
St'),(30,5,'166801632','Charlotte','Lopez','2006-10-23','New Mexico','46592','Everett','Lunar
Ave'),(31,7,'612015918','Harper','Gonzalez','1985-04-13','New York','49535','Franklin','Majestic
St'),(32,9,'671659478','Elijah','Wilson','2006-06-28','North Carolina','83475','Glendale','Nirvana
Rd'),(33,2,'872380592','Amelia','Anderson','1990-03-25','North Dakota','96332','Harrison','Oracle
Way'),(34,8,'440255665','Lucas','Thomas','1978-02-08','Ohio','48140','Irvine','Pleasant
St'),(35,9,'411597999','Evelyn','Jackson','2000-03-17','Oklahoma','43021','Jefferson','Quiet
Ave'),(36,1,'738950678','Mason','White','1943-06-05','Oregon','51047','Kenton','Radiant
St'),(37,7,'744637315','Abigail','Harris','1989-11-12','Pennsylvania','92168','Lancaster','Sunset
Blvd'),(38,7,'389775362','William','Martin','1965-10-19','Rhode Island','21297','Mesa','Arcane
St'),(39,8,'837743759','Scarlett','Thompson','2021-07-27','South
Carolina','75177','Newport','Blessed Rd'),(40,1,'508644852','Emma','Smith','1940-12-28','South
Dakota','77566','Oakland','Celestial
Ave'),(41,5,'299224085','Liam','Johnson','1980-10-15','Tennessee','51308','Portsmouth','Dream
Blvd'),(42,4,'456620252','Olivia','Williams','1972-12-09','Texas','65450','Quincy','Elysian
St'),(43,5,'486196332','Noah','Jones','1948-11-23','Utah','62500','Raleigh','Fantasy
Rd'),(44,8,'348115212','Ava','Brown','1966-02-15','Vermont','40392','Savannah','Gates
St'),(45,10,'390797499','Isabella','Davis','1954-06-08','Virginia','41365','Tacoma','Haven
Ave'),(46,9,'396804847','Sophia','Garcia','2014-11-28','Washington','94213','Union','Infinite
Way'),(47,8,'482991147','Jackson','Rodriguez','1999-03-30','West
Virginia','62844','Ventura','Jewel
Rd'),(48,5,'872733055','Mia','Martinez','2005-06-10','Wisconsin','92579','Waltham','Kismet
St'),(49,4,'262145524','Aiden','Hernandez','1988-02-08','Wyoming','97806','Xenia','Lunar
Ave'),(50,4,'404944741','Charlotte','Lopez','2010-11-08','Alabama','25288','Yuma','Majestic
St'),(51,8,'377881391','Harper','Gonzalez','2019-05-18','Alaska','43486','Zion','Nirvana
Rd'),(52,6,'443597370','Elijah','Wilson','1989-12-08','Arizona','39670','Aurora','Oracle
Way'),(53,3,'893821310','Amelia','Anderson','1981-08-27','Arkansas','87366','Bristol','Pleasant
St'),(54,7,'265318216','Lucas','Thomas','2022-08-06','California','58181','Chandler','Quiet
Ave'),(55,10,'199884886','Evelyn','Jackson','2008-03-01','Colorado','48653','Dover','Radiant
St'),(56,7,'526298235','Mason','White','1977-06-19','Connecticut','27258','Everett','Sunset
Blvd'),(57,6,'274462918','Abigail','Harris','1943-04-17','Delaware','21009','Franklin','Arcane
St'),(58,8,'801068756','William','Martin','1973-04-10','Florida','98582','Glendale','Blessed
Rd'),(59,10,'544235890','Scarlett','Thompson','1974-12-08','Georgia','40249','Harrison','Celestial
Ave'),(60,1,'738212270','Emma','Smith','1955-09-28','Hawaii','10134','Irvine','Dream
Blvd'),(61,3,'212187137','Liam','Johnson','2007-11-11','Idaho','31826','Jefferson','Elysian
St'),(62,1,'877065080','Olivia','Williams','1950-02-02','Illinois','57854','Kenton','Fantasy
Rd'),(63,5,'683692607','Noah','Jones','1953-07-27','Indiana','85528','Lancaster','Gates
St'),(64,5,'399926882','Ava','Brown','1966-08-24','Iowa','84429','Mesa','Haven
Ave'),(65,3,'370896915','Isabella','Davis','1983-01-29','Kansas','45019','Newport','Infinite
Way'),(66,3,'791481834','Sophia','Garcia','2003-07-26','Kentucky','17170','Oakland','Jewel
Rd'),(67,5,'797247998','Jackson','Rodriguez','1959-09-04','Louisiana','17153','Portsmouth','Kism
et St'),(68,8,'737497907','Mia','Martinez','1968-03-06','Maine','95338','Quincy','Lunar
Ave'),(69,7,'774557433','Aiden','Hernandez','1979-07-29','Maryland','57081','Raleigh','Majestic
St'),(70,8,'615376901','Charlotte','Lopez','1999-09-07','Massachusetts','43935','Savannah','Nirva
na Rd'),(71,3,'482858736','Harper','Gonzalez','2002-07-01','Michigan','50306','Tacoma','Oracle
Way'),(72,2,'406072227','Elijah','Wilson','1943-08-07','Minnesota','27075','Union','Pleasant
St'),(73,4,'482863441','Amelia','Anderson','2006-05-13','Mississippi','90496','Ventura','Quiet
Ave'),(74,2,'120384936','Lucas','Thomas','1977-10-11','Missouri','62438','Waltham','Radiant
St'),(75,1,'445616983','Evelyn','Jackson','1944-04-02','Montana','57923','Xenia','Sunset
Blvd'),(76,10,'412349265','Mason','White','1988-01-08','Nebraska','68607','Yuma','Arcane
St'),(77,4,'640156905','Abigail','Harris','1970-07-31','Nevada','99357','Zion','Blessed
Rd'),(78,1,'818264990','William','Martin','1949-09-07','New Hampshire','14583','Aurora','Celestial
Ave'),(79,3,'222758938','Scarlett','Thompson','1954-02-01','New Jersey','88930','Bristol','Dream
Blvd'),(80,10,'394573984','Emma','Smith','1951-03-21','New Mexico','90870','Chandler','Elysian
St'),(81,9,'608818319','Liam','Johnson','1976-03-30','New York','22803','Dover','Fantasy
Rd'),(82,3,'520669520','Olivia','Williams','1977-04-15','North Carolina','91588','Everett','Gates
St'),(83,9,'126805959','Noah','Jones','1948-07-10','North Dakota','39910','Franklin','Haven
Ave'),(84,2,'634945922','Ava','Brown','1941-04-09','Ohio','34251','Glendale','Infinite
Way'),(85,10,'245578781','Isabella','Davis','2004-04-27','Oklahoma','16733','Harrison','Jewel
Rd'),(86,9,'546059710','Sophia','Garcia','2020-01-26','Oregon','59774','Irvine','Kismet
St'),(87,3,'473691084','Jackson','Rodriguez','1994-12-07','Pennsylvania','59593','Jefferson','Luna
r Ave'),(88,8,'671180331','Mia','Martinez','2014-01-17','Rhode Island','52577','Kenton','Majestic
St'),(89,7,'705345187','Aiden','Hernandez','1975-10-01','South
Carolina','37677','Lancaster','Nirvana
Rd'),(90,6,'379577716','Charlotte','Lopez','1951-03-23','South Dakota','66960','Mesa','Oracle
Way'),(91,2,'777051900','Harper','Gonzalez','2012-09-07','Tennessee','65153','Newport','Pleasan
t St'),(92,1,'295266449','Elijah','Wilson','2021-05-01','Texas','39087','Oakland','Quiet
Ave'),(93,5,'116196072','Amelia','Anderson','2016-11-09','Utah','11015','Portsmouth','Radiant
St'),(94,8,'694419062','Lucas','Thomas','1967-02-19','Vermont','28711','Quincy','Sunset
Blvd'),(95,9,'328654434','Evelyn','Jackson','1988-05-05','Virginia','62798','Raleigh','Arcane
St'),(96,3,'348278497','Mason','White','1949-03-21','Washington','35499','Savannah','Blessed
Rd'),(97,5,'676517725','Abigail','Harris','1962-11-12','West Virginia','10887','Tacoma','Celestial
Ave'),(98,6,'380553824','William','Martin','1943-12-05','Wisconsin','18296','Union','Dream
Blvd'),(99,8,'405599758','Scarlett','Thompson','1992-10-27','Wyoming','72222','Ventura','Elysian
St'),(100,6,'126598424','Emma','Smith','1981-06-22','Alabama','60089','Waltham','Fantasy Rd');
/*!40000 ALTER TABLE `patient` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `pharmacy`
--

DROP TABLE IF EXISTS `pharmacy`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `pharmacy` (
`pharmacyId` int NOT NULL AUTO_INCREMENT,
`pharmacyName` varchar(45) NOT NULL,
`pharmacyPhone` varchar(17) NOT NULL,
`pharmacyZip` varchar(9) NOT NULL,
`pharmacyCity` varchar(45) NOT NULL,
`pharmacyStreet` varchar(45) NOT NULL,
PRIMARY KEY (`pharmacyId`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `pharmacy`
--

LOCK TABLES `pharmacy` WRITE;


/*!40000 ALTER TABLE `pharmacy` DISABLE KEYS */;
INSERT INTO `pharmacy` VALUES (1,'HealthRx','5551234567','91802','Aurora','Arcane
St'),(2,'MediCore','5552345678','28071','Bristol','Blessed
Rd'),(3,'PillHub','5553345679','42510','Chandler','Celestial
Ave'),(4,'WellRx','5554356789','53854','Dover','Dream
Blvd'),(5,'VitalRx','5555456789','71048','Everett','Elysian
St'),(6,'RxSure','5556567890','74787','Franklin','Fantasy
Rd'),(7,'ComfortRx','5557678901','15770','Glendale','Gates
St'),(8,'EssenRx','5558789012','68518','Harrison','Haven
Ave'),(9,'ChoiceRx','5559878901','62256','Irvine','Infinite
Way'),(10,'LifeRx','5551098765','50473','Jefferson','Jewel Rd');
/*!40000 ALTER TABLE `pharmacy` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `pharmacydrug`
--

DROP TABLE IF EXISTS `pharmacydrug`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `pharmacydrug` (
`pharmacyId` int NOT NULL,
`drugId` int NOT NULL,
`price` int NOT NULL,
PRIMARY KEY (`pharmacyId`,`drugId`),
KEY `fk_pharmacyDrug_pharmacy1_idx` (`pharmacyId`),
KEY `fk_pharmacyDrug_drug1_idx` (`drugId`),
CONSTRAINT `fk_pharmacyDrug_drug1` FOREIGN KEY (`drugId`) REFERENCES `drug`
(`drugId`),
CONSTRAINT `fk_pharmacyDrug_pharmacy1` FOREIGN KEY (`pharmacyId`) REFERENCES
`pharmacy` (`pharmacyId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `pharmacydrug`
--

LOCK TABLES `pharmacydrug` WRITE;


/*!40000 ALTER TABLE `pharmacydrug` DISABLE KEYS */;
INSERT INTO `pharmacydrug` VALUES
(1,34,96),(1,64,54),(1,71,68),(1,80,41),(1,83,13),(1,86,87),(1,90,47),(2,9,23),(2,16,78),(2,36,91),
(2,51,1),(2,63,61),(2,65,76),(2,95,65),(2,96,58),(3,26,31),(3,40,33),(3,44,87),(3,45,13),(3,47,45),
(3,50,13),(3,52,40),(3,58,25),(3,67,79),(3,77,99),(3,85,21),(3,92,96),(4,21,23),(4,28,42),(4,30,98)
,(4,35,83),(4,38,7),(4,81,19),(4,89,12),(5,8,82),(5,22,54),(5,27,62),(5,33,98),(5,37,25),(5,43,55),(
5,57,52),(5,59,90),(5,72,51),(5,84,85),(5,97,64),(5,98,94),(6,1,100),(6,17,1),(6,29,18),(6,31,88),(
6,32,79),(6,49,21),(6,53,93),(6,73,44),(6,82,93),(6,87,83),(6,94,96),(7,4,15),(7,7,92),(7,10,23),(7,
11,37),(7,15,23),(7,18,80),(7,19,64),(7,42,52),(7,46,24),(7,48,86),(7,55,55),(7,60,92),(7,70,37),(7
,74,72),(7,76,2),(7,79,39),(7,88,33),(8,2,53),(8,3,47),(8,5,46),(8,12,45),(8,13,42),(8,25,69),(8,61,
29),(8,66,12),(8,68,75),(8,69,62),(8,91,37),(8,93,30),(9,14,16),(9,24,44),(9,39,61),(9,56,28),(9,62
,60),(9,78,95),(10,6,41),(10,20,98),(10,23,37),(10,41,33),(10,54,60),(10,75,62),(10,99,100);
/*!40000 ALTER TABLE `pharmacydrug` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `prescription`
--

DROP TABLE IF EXISTS `prescription`;


/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `prescription` (
`rxNum` int NOT NULL AUTO_INCREMENT,
`doctorId` int NOT NULL,
`patientId` int NOT NULL,
`drugId` int NOT NULL,
`prescribeDate` date NOT NULL,
`quantity` int NOT NULL,
PRIMARY KEY (`rxNum`),
KEY `fk_prescription_drug1_idx` (`drugId`),
KEY `fk_prescription_patient1_idx` (`patientId`),
KEY `fk_prescription_doctor1_idx` (`doctorId`),
CONSTRAINT `fk_prescription_doctor1` FOREIGN KEY (`doctorId`) REFERENCES `doctor`
(`doctorId`),
CONSTRAINT `fk_prescription_drug1` FOREIGN KEY (`drugId`) REFERENCES `drug`
(`drugId`),
CONSTRAINT `fk_prescription_patient1` FOREIGN KEY (`patientId`) REFERENCES `patient`
(`patientId`)
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `prescription`
--

LOCK TABLES `prescription` WRITE;


/*!40000 ALTER TABLE `prescription` DISABLE KEYS */;
INSERT INTO `prescription` VALUES
(1,3,6,13,'2022-03-01',4),(2,1,35,81,'2020-09-18',4),(3,7,22,93,'2020-12-26',6),(4,2,34,36,'2021-
02-02',2),(5,2,33,37,'2020-01-23',1),(6,3,77,6,'2020-05-20',5),(7,4,99,43,'2020-03-01',10),(8,4,44
,94,'2021-08-27',6),(9,1,56,48,'2020-12-18',7),(10,2,80,66,'2021-04-15',8),(11,6,37,44,'2022-11-1
7',7),(12,2,35,52,'2021-12-05',7),(13,10,89,99,'2020-06-01',2),(14,9,97,83,'2021-07-21',9),(15,6,
96,72,'2020-09-21',3),(16,7,84,91,'2022-12-29',4),(17,8,90,38,'2021-10-21',10),(18,9,89,74,'202
1-07-11',7),(19,5,29,5,'2020-05-05',9),(20,10,73,42,'2022-03-23',2),(21,6,46,18,'2021-02-10',7),(
22,2,60,7,'2020-07-12',5),(23,7,87,83,'2022-11-07',2),(24,2,88,54,'2022-01-07',5),(25,2,80,92,'20
22-01-14',3),(26,1,82,36,'2022-08-07',6),(27,2,97,78,'2022-11-04',4),(28,9,64,14,'2021-12-12',6),
(29,10,53,52,'2022-06-13',4),(30,9,73,37,'2022-04-05',2),(31,7,77,12,'2022-05-17',5),(32,7,60,96
,'2020-03-23',3),(33,9,97,74,'2022-12-21',7),(34,1,48,86,'2022-12-10',2),(35,8,30,4,'2020-07-02',
6),(36,9,4,44,'2022-04-11',6),(37,2,26,13,'2022-09-29',8),(38,7,28,17,'2021-08-18',4),(39,10,54,8
9,'2021-12-05',2),(40,8,46,57,'2021-08-16',7),(41,4,39,47,'2021-12-05',7),(42,8,10,5,'2022-12-31
',2),(43,3,76,63,'2021-04-09',9),(44,7,38,17,'2022-04-30',7),(45,8,68,1,'2020-06-30',6),(46,3,98,3
,'2021-06-03',7),(47,10,94,94,'2021-12-30',1),(48,4,16,96,'2022-11-14',4),(49,8,8,82,'2020-01-13'
,7),(50,10,64,23,'2022-02-23',9),(51,2,86,39,'2021-11-06',2),(52,8,57,24,'2021-08-22',4),(53,8,97
,73,'2021-12-17',2),(54,10,98,3,'2021-03-30',8),(55,7,9,16,'2021-10-03',4),(56,5,85,36,'2020-11-
26',5),(57,5,20,87,'2022-05-25',8),(58,10,39,10,'2020-12-26',2),(59,7,66,31,'2022-08-19',10),(60,
10,57,71,'2020-09-06',5),(61,3,7,32,'2022-04-24',3),(62,9,24,37,'2020-11-19',7),(63,8,54,4,'2020-
06-06',1),(64,10,22,99,'2021-11-08',10),(65,6,57,92,'2020-02-21',2),(66,7,62,13,'2021-10-24',4),(
67,7,62,3,'2020-11-02',1),(68,4,39,99,'2021-07-02',10),(69,7,43,37,'2022-01-20',3),(70,6,24,38,'2
022-05-07',10),(71,1,94,80,'2022-08-28',1),(72,6,85,45,'2020-08-22',9),(73,9,41,47,'2022-05-19',
2),(74,5,97,60,'2020-12-27',2),(75,7,99,33,'2021-09-01',7),(76,1,2,16,'2022-04-27',10),(77,8,81,7
4,'2021-04-30',9),(78,2,99,46,'2021-08-17',2),(79,4,33,71,'2022-01-30',8),(80,1,48,35,'2020-06-1
3',9),(81,7,82,90,'2021-02-28',6),(82,6,4,9,'2020-07-16',4),(83,9,56,27,'2021-02-02',2),(84,8,98,6
9,'2021-08-24',1),(85,9,28,78,'2022-05-10',3),(86,8,20,73,'2020-12-02',2),(87,5,30,71,'2022-02-2
7',9),(88,10,58,92,'2021-01-25',5),(89,4,10,37,'2021-11-30',3),(90,3,48,93,'2021-02-20',7),(91,9,
43,74,'2022-08-06',3),(92,6,63,24,'2021-03-29',4),(93,2,18,90,'2020-01-24',8),(94,2,44,89,'2020-
11-06',3),(95,10,91,2,'2021-11-30',6),(96,8,32,8,'2022-10-02',4),(97,7,53,52,'2020-12-16',3),(98,
4,36,21,'2022-05-14',5),(99,6,10,18,'2022-01-21',10),(100,3,14,32,'2021-01-01',9);
/*!40000 ALTER TABLE `prescription` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;


/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2023-02-07 21:46:25

-- Select all of the expired contract ids that a pharmacy had with any pharmaceutical company.
SELECT contractId FROM contract c, pharmacy p
WHERE c.endDate < CURDATE()
AND c.pharmacyId = p.pharmacyId AND p.pharmacyName = 'targetPharmacyName';

-- Select all of the distinct drugs by tradeName that a specific doctor (by SSN) has written
prescriptions for.
SELECT DISTINCT tradeName
FROM prescription p, doctor doc, drug d
WHERE p.doctorId = doc.doctorId
AND p.drugId = d.drugId
AND doc.doctorSSN = 'targetSSN'
AND d.tradeName IS NOT NULL;

-- Select all of the distinct generic drug names that at least one patient has been prescribed.
SELECT DISTINCT genericName
FROM drug
WHERE drugId IN
(SELECT drugId
FROM prescription
WHERE rxNum IS NOT NULL);

-- Select the pharmacy name(s) that sell a specific drug by generic name with the lowest price.
SELECT DISTINCT p.pharmacyName
FROM pharmacy p
JOIN pharmacyDrug pd on p.pharmacyId = pd.pharmacyId
JOIN drug d ON pd.drugId = d.drugId
WHERE genericName = 'targetDrugGenericName'
AND price = (
SELECT MIN(price)
FROM pharmacyDrug pd, drug d
WHERE pd.drugId = d.drugId
AND genericName = 'targetDrugGenericName'
);

-- Select the average age of patients that have prescriptions filled through a specific pharmacy
SELECT AVG(YEAR(CURDATE())-YEAR(p.patientBirthdate)) as "Average Age"
FROM prescription AS pr
JOIN patient AS p ON pr.patientId = p.patientId
JOIN fill AS f ON f.rxNum = pr.rxNum
JOIN pharmacy AS ph ON f.pharmacyID = ph.pharmacyId
WHERE ph.pharmacyName = 'targetPharmacyName';

You might also like