Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an ER Diagram based off this code: - - Create the database CREATE DATABASE HospitalDB; USE HospitalDB; - - Create the Patient table CREATE

Create an ER Diagram based off this code:
-- Create the database
CREATE DATABASE HospitalDB;
USE HospitalDB;
-- Create the Patient table
CREATE TABLE Patient (
PatientID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
ContactInfo VARCHAR(150),
Address VARCHAR(255),
Age INT,
Weight DECIMAL(5,2),
Height DECIMAL(5,2),
InsuranceInfo VARCHAR(150),
SSN VARCHAR(11) UNIQUE
);
-- Create the Doctor table
CREATE TABLE Doctor (
DoctorID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Specialization VARCHAR(100),
ContactInfo VARCHAR(150)
);
-- Create the Room table
CREATE TABLE Room (
RoomNumber INT PRIMARY KEY,
RoomType VARCHAR(50),
Availability BOOLEAN
);
-- Create the Staff table
CREATE TABLE Staff (
StaffID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Role VARCHAR(100),
ContactInfo VARCHAR(150)
);
-- Create the Treatment table
CREATE TABLE Treatment (
TreatmentID INT AUTO_INCREMENT PRIMARY KEY,
TreatmentDetails TEXT,
Date DATE,
StaffID INT,
PatientID INT,
FOREIGN KEY (StaffID) REFERENCES Staff(StaffID),
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID)
);
-- Create the Patient_Doctor table for the many-to-many relationship
CREATE TABLE Patient_Doctor (
PatientID INT,
DoctorID INT,
PRIMARY KEY (PatientID, DoctorID),
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID),
FOREIGN KEY (DoctorID) REFERENCES Doctor(DoctorID)
);
-- Create the Patient_Room table for the one-to-one relationship
CREATE TABLE Patient_Room (
PatientID INT,
RoomNumber INT,
AdmissionDate DATE,
DischargeDate DATE,
PRIMARY KEY (PatientID, RoomNumber),
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID),
FOREIGN KEY (RoomNumber) REFERENCES Room(RoomNumber)
);
-- Create the Patient_Treatment table for the one-to-many relationship
CREATE TABLE Patient_Treatment (
PatientID INT,
TreatmentID INT,
PRIMARY KEY (PatientID, TreatmentID),
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID),
FOREIGN KEY (TreatmentID) REFERENCES Treatment(TreatmentID)
);
-- Create the Staff_Treatment table for the one-to-many relationship
CREATE TABLE Staff_Treatment (
StaffID INT,
TreatmentID INT,
PRIMARY KEY (StaffID, TreatmentID),
FOREIGN KEY (StaffID) REFERENCES Staff(StaffID),
FOREIGN KEY (TreatmentID) REFERENCES Treatment(TreatmentID)
);
Use entites with the bubbles and lines.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions