Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

‫اماةةةةةةةةةةةةة‬ ‫اةةةةةةةةةةةةة‬ ‫جامعةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةة عةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةةة‬

‫يةةةة‬ ‫عملةةةة ةةةةةرا‬ ‫كليةةة سة اةةة ميكاةيكيةةة ي كس ا يةةة‬


‫اةةةة ‪2024‬‬ ‫عةةةةاا‬ ‫هة اةةةةةة ةةةةةةلحكا ب ةةةةةة ي حي اةةةةةةي‬

‫‪Design of a Pharmacy Database‬‬

‫إعداد ‪:‬‬

‫إشراف ‪:‬‬

‫‪1‬‬
‫مخطط الكيان والعالقة‬ 

‫إنشاء قاعدة البيانات‬ 

CREATE DATABASE Pharmacy; CREATE TABLE Addresses


USE Pharmacy; (
Hospital_Name char(50) NOT NULL,
Hospital_ID int NOT NULL,
City char(50) NOT NULL,
State_ char(50) NULL,
Country char(50) NULL,
Zip_Code char(10) NULL,
CREATE TABLE Customers Physician_ID char(10) NOT NULL,
( PRIMARY KEY (Hospital_ID)
Customer_ID int NOT NULL, );
Customer_Name char(30) NOT NULL,
DOP char(30) NOT NUll, CREATE TABLE Physicians
Gender char(10) NOT NULL, (
PRIMARY KEY (Customer_ID) Physician_ID char(10) NOT NULL,
); Physician_Name char(30) NOT NULL,
Physician_Details char(50) NULL,
Hospital_Name char(50) NULL,
PRIMARY KEY (Physician_ID)
);

2
CREATE TABLE Prescriptions
(
Prescription_ID int NOT NULL,
Customer_ID int NOT NULL,
Physician_ID char(10) NOT NULL,
PID char(20) NULL,
PFD char(20) NULL,
PRIMARY KEY (Prescription_ID),
CONSTRAINT Customers_Prescriptions_Fk FOREIGN KEY (Customer_ID)
REFERENCES Customers (Customer_ID),
CONSTRAINT Physicians_Prescriptions_Fk FOREIGN KEY (Physician_ID)
REFERENCES Physicians (Physician_ID)
);

CREATE TABLE Prescription_Items


(
Prescription_ID int NOT NULL,
Drug_ID int NOT NULL,
Medicines_Names char(100) NOT NULL,
Quantity int NOT NULL,
ITC char(30) NOT NULL,
DOE char(30) NOT NULL,
Hospital_ID int NOT NULL,
PRIMARY KEY (Drug_ID),
CONSTRAINT Prescriptions_Prescription_Items_Fk FOREIGN KEY (Prescription_ID)
REFERENCES Prescriptions (Prescription_ID),
CONSTRAINT Addresses_Prescriptions_Fk FOREIGN KEY (Hospital_ID)
REFERENCES Addresses (Hospital_ID)
);

‫تعبئة الجداول‬ 

INSERT INTO Customers(Customer_ID,Customer_Name,DOP,Gender)


VALUES
('1','Mariyam','15/10/2023','Female'),
('2','Mohamad','20/10/2023','Male'),
('3','Ali','21/10/2023','Male'),
('4','Karam','22/10/2023','Male');

INSERT INTO Addresses (Hospital_Name,Hospital_ID,Country, City,State_, Zip_Code,


Physician_ID)
VALUES
('Smith County Memorial Hospital', '2522','Smith Center', 'USA', 'KS', '66967',
'236464'),
('Rooks County Health Center','8757', 'Plainville', 'USA', 'KS', '67663', '456421'),
('Osborne County Memorial Hospital','4245', 'Osborne', 'USA', 'KS', '67473', '536526'),
('Franklin County Memorial Hospital45 ','4578','Franklin','USA', 'NE', '68939',
'654984');

INSERT INTO Physicians (Physician_ID, Physician_Name,Physician_Details, Hospital_Name)


VALUES
('236464', 'Dr. Sarah Lee', 'Urologist','Smith County Memorial Hospital'),
('456421', 'Dr. Alex Brown', 'radiologist','Rooks County Health Center'),
('536526', 'Dr. Lisa White','Peditritian', 'Osborne County Memorial Hospital'),
('654984', 'Dr. Mark Black', 'Neuorologist','Franklin County Memorial Hospital45');

3
INSERT INTO Prescriptions (Prescription_ID,Customer_ID, Physician_ID, PID,PFD)
VALUES
('001','1', '236464', '',''),
('002','2', '456421', '',''),
('003','3', '536526', '',''),
('004','4', '654984', '','');

INSERT INTO Prescription_Items (Prescription_ID, Drug_ID,Medicines_Names, Quantity, ITC,


DOE, Hospital_ID)
VALUES
('001', '2585894','ALP',2, '1 tablest daily', '22/10/2025', '2522'),
('002', '6575341','Neubrol Forte', 3, '3 tablests daily', '30/10/2025', '8757'),
('003', '5545631','Atarex', 1, '1 tablest daily', '20/11/2025', '4245'),
('004', '7575312','Panadol', 2, '2 tablests daily', '5/3/2024', '4578');

‫االستعالم‬ 

SELECT *
FROM Addresses;

SELECT Customer_Name , Gender


FROM Customers;

SELECT Prescription_ID , Drug_ID ,Medicines_Names,Quantity


FROM Prescription_Items
WHERE Hospital_ID = '4578';

You might also like