Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i need help with sql code highlighted . i keep getting this Error Code: 1 4 5 2 . Cannot add or update a child
i need help with sql code highlighted i keep getting this Error Code: Cannot add or update a child row: a foreign key constraint fails healthcarebilling CONSTRAINT billingibfk FOREIGN KEY RecordID REFERENCES medicalrecordRecordID dont know what i did wrong Here is my full sql code CREATE SCHEMA healthcare;
Use healthcare;
CREATE TABLE Patient
PatientID INT PRIMARY KEY,
PatientName VARCHAR NOT NULL,
PatientAddress VARCHAR NOT NULL,
Contact VARCHAR NOT NULL,
Insurance VARCHAR NOT NULL
;
CREATE TABLE Doctor
DoctorID INT PRIMARY KEY,
Name VARCHAR NOT NULL,
Specialization VARCHAR NOT NULL,
Contact VARCHAR NOT NULL
;
CREATE TABLE Appointment
RecordID INT PRIMARY KEY,
PatientID INT,
DoctorID INT,
Date DATETIME NOT NULL,
FOREIGN KEY PatientID REFERENCES PatientPatientID
FOREIGN KEY DoctorID REFERENCES DoctorDoctorID
;
CREATE TABLE MedicalRecord
RecordID INT PRIMARY KEY,
PatientID INT,
Diagnosis VARCHAR NOT NULL,
Treatment VARCHAR NOT NULL,
FOREIGN KEY PatientID REFERENCES PatientPatientID
;
CREATE TABLE Billing
CREATE TABLE Billing
BillingID INT PRIMARY KEY,
RecordID INT,
PatientID INT,
TotalAmount DECIMAL NOT NULL,
PaymentStatus VARCHAR NOT NULL,
FOREIGN KEY RecordID REFERENCES MedicalRecordRecordID
FOREIGN KEY PatientID REFERENCES PatientPatientID
;
ALTER TABLE MedicalReco rd
ADD CONSTRAINT FKMedicalRecordAppointment
FOREIGN KEY RecordID
REFERENCES AppointmentRecordID;
INSERT INTO Patient PatientID PatientName, PatientAddress, Contact, Insurance
VALUES
'John Doe', Main St Anytown, CA 'Aetna'
'Jane Smith', Elm St Anytown, CA 'Blue Cross Blue Shield'
'Mike Jones', Oak St Anytown, CA 'Cigna'
'Alice Lee', Cedar St Anytown, CA 'UnitedHealthcare'
'Bob Brown', Walnut St Anytown, CA 'Humana';
INSERT INTO Patient PatientID PatientName, PatientAddress, Contact, Insurance
VALUES
'John Doe', Main St Anytown, CA 'Aetna'
'Jane Smith', Elm St Anytown, CA 'Blue Cross Blue Shield'
'Mike Jones', Oak St Anytown, CA 'Cigna'
'Alice Lee', Cedar St Anytown, CA 'UnitedHealthcare'
'Bob Brown', Walnut St Anytown, CA 'Humana';
INSERT INTO Doctor DoctorID Name, Specialization, Contact
VALUES
Dr Smith', 'General Medicine',
Dr Jones', 'Cardiology',
Dr Lee', 'Dermatology',
Dr Brown', 'Neurology',
Dr Williams', 'Orthopedics', ;
INSERT INTO Appointment RecordID PatientID, DoctorID, Date
VALUES
;
INSERT INTO MedicalRecord RecordID PatientID, Diagnosis, Treatment
VALUES
'Hypertension', 'Medications, lifestyle changes'
'Eczema', 'Topical steroids, emollients'
'Anxiety', 'Therapy, medication'
'Migraine headaches', 'Pain medication, preventive medication'
'Knee pain', 'Physical therapy, pain medication';
INSERT INTO Billing BillingID RecordID, PatientID, TotalAmount, PaymentStatus
VALUES
'Paid'
'Paid'
'Paid'
'Paid'
'Paid'
'Paid'
'Paid'
'Paid';
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started