Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Revised_SQL_Script_MySQL_Compatible

The document provides a revised SQL script for creating tables in a MySQL database, including Employee, Department, Patient, Diagnosis, Insurance, Appointment, Doctor, Bill, Dependent_Name, and Doctor_Qualification tables. It also includes a trigger to update the Payment_Status in the Bill table based on the comparison of Total_Amount and Amount_Paid. Each table is defined with appropriate fields and foreign key relationships to ensure data integrity.

Uploaded by

Paarth Prakash
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Revised_SQL_Script_MySQL_Compatible

The document provides a revised SQL script for creating tables in a MySQL database, including Employee, Department, Patient, Diagnosis, Insurance, Appointment, Doctor, Bill, Dependent_Name, and Doctor_Qualification tables. It also includes a trigger to update the Payment_Status in the Bill table based on the comparison of Total_Amount and Amount_Paid. Each table is defined with appropriate fields and foreign key relationships to ensure data integrity.

Uploaded by

Paarth Prakash
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Revised SQL Script for MySQL Compatibility

Employee Table

CREATE TABLE Employee (


E_Id INT PRIMARY KEY,
D_Id INT,
Name VARCHAR(255) NOT NULL,
Salary DECIMAL(10,2),
Sex VARCHAR(10),
Mob_No VARCHAR(15) NOT NULL UNIQUE,
Address VARCHAR(255),
Joining_Date DATE,
`CurrentDate` DATE
);

Department Table

CREATE TABLE Department (


D_Id INT PRIMARY KEY,
D_Name VARCHAR(255),
HOD_Id INT
);

Patient Table

CREATE TABLE Patient (


P_Id INT PRIMARY KEY,
F_Name VARCHAR(255) NOT NULL,
M_Name VARCHAR(255),
L_Name VARCHAR(255),
DOB DATE,
Gender VARCHAR(10),
Mnum VARCHAR(15) NOT NULL UNIQUE,
Address VARCHAR(255),
Dis_Date DATE,
Ad_Date DATE,
I_Id INT
);
Diagnosis Table

CREATE TABLE Diagnosis (


Diagnosis_Id INT PRIMARY KEY,
P_Id INT,
D_Id INT,
FOREIGN KEY (P_Id) REFERENCES Patient(P_Id),
FOREIGN KEY (D_Id) REFERENCES Department(D_Id)
);

Insurance Table

CREATE TABLE Insurance (


I_no INT PRIMARY KEY,
P_Id INT,
TCA INT,
Used_amt INT,
Starting_Date DATE,
Val_P DATE,
Rem_amt INT GENERATED ALWAYS AS (TCA - Used_amt) STORED,
FOREIGN KEY (P_Id) REFERENCES Patient(P_Id)
);

Appointment Table

CREATE TABLE Appointment (


A_Id INT PRIMARY KEY,
P_Id INT,
Doctor_Id INT,
A_Date DATE NOT NULL,
A_Time TIME NOT NULL,
FOREIGN KEY (P_Id) REFERENCES Patient(P_Id),
FOREIGN KEY (Doctor_Id) REFERENCES Doctor(Doctor_Id)
);

Doctor Table

CREATE TABLE Doctor (


Doctor_Id INT PRIMARY KEY,
E_Id INT,
C_Fee INT,
Available_From TIME,
Available_To TIME,
FOREIGN KEY (E_Id) REFERENCES Employee(E_Id)
);

Bill Table

CREATE TABLE Bill (


B_Id INT PRIMARY KEY,
P_Id INT,
Total_Amount DECIMAL(10,2) NOT NULL,
Bill_Date DATE NOT NULL,
Amount_Paid DECIMAL(10,2),
Payment_Status VARCHAR(10),
FOREIGN KEY (P_Id) REFERENCES Patient(P_Id)
);

Dependent_Name Table

CREATE TABLE Dependent_Name (


Dependent_Id INT PRIMARY KEY,
E_Id INT,
Dependent_Name VARCHAR(255),
FOREIGN KEY (E_Id) REFERENCES Employee(E_Id)
);

Doctor_Qualification Table

CREATE TABLE Doctor_Qualification (


Qualification_Id INT PRIMARY KEY,
Doctor_Id INT,
Qualification VARCHAR(255),
FOREIGN KEY (Doctor_Id) REFERENCES Doctor(Doctor_Id)
);

Trigger for Payment_Status

DELIMITER //
CREATE TRIGGER UpdatePaymentStatus
AFTER UPDATE ON Bill
FOR EACH ROW
BEGIN
IF NEW.Total_Amount = NEW.Amount_Paid THEN
SET NEW.Payment_Status = 'Paid';
ELSE
SET NEW.Payment_Status = 'Unpaid';
END IF;
END //

DELIMITER ;

You might also like