Bonus: Database Design for a Doctor Clinic
What's in this guide
This guide goes with my YouTube video on designing a database for a doctor's clinic. In it, you'll find:
- The Entity Relationship Diagram for a doctor clinic from the video
- An explanation of the purpose of each table and column, with sample data
- An SQL script to create each of these tables
Prefer a PDF? You can download the PDF version of this guide.
Entity Relationship Diagram
Here's the ERD for this database:
The Tables
This section explains each of the 13 tables and their columns.
patient
A record of patients, which is one of the core tables in the database.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| first_name | The first name of the patient. |
| last_name | The last name of the patient. |
| gender_id | A foreign key to the gender table to store the patient's gender. |
| date_of_birth | The date of birth of the patient, which the doctor can use to see how old they are. |
| phone_number | The patient's phone number. |
| email_address | The patient's email address. |
| address_line1 | Part of the patient's address. |
| address_line2 | Part of the patient's address. |
| state | Part of the patient's address. |
| country_id | The foreign key for the country of the patient's address. |
| created_at | The date and time the record was created. |
| Learn how to design an effective database & create it with SQL | 2 |
country
A lookup table for the different countries.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| city_name | The name of the country. |
doctor
A record of all the doctors in the clinic.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| first_name | The first name of the doctor. |
| last_name | The last name of the doctor. |
| gender_id | A foreign key to the gender table to store the doctor's gender. |
| created_at | The date and time the record was created. |
gender
A lookup table for the genders of patients and doctors.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| name | The value of the gender. |
specialisation
A lookup table for the different specialisations of doctors.
| Column | Description |
|---|---|
| Learn how to design an effective database & create it with SQL | 3 |
| id | Primary key. A unique identifier for the row. |
| name | The specialisation that a doctor can have, such as Mental Health or Women's Health |
doctor_specialisations
A joining table for doctors and specialisations.
| Column | Description |
|---|---|
| doctor_id | A foreign key for the doctor. |
| specialisation_id | A foreign key for the specialisation. |
appointment
A record of an appointment made for a patient.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| patient_id | A foreign key to the patient table, representing the patient of the appointment. |
| doctor_id | A foreign key to the doctor table. |
| appointment_datetime | The date and time of the appointment. |
| status_id | A foreign key to the appointment_status table, to indicate the status of the appointment. |
| reason | The reason for making the appointment. |
| created_at | The date and time the record was created. |
appointment_status
A lookup table for the status of an appointment.
| Column | Description |
|---|---|
| Learn how to design an effective database & create it with SQL | 4 |
| id | Primary key. A unique identifier for the row. |
| name | The value for the status, such as Scheduled or Cancelled. |
appointment_note
A record of a note made for an appointment.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| appointment_id | A foreign key to the appointment table. |
| notes | A large text field to capture the notes. |
| created_at | The date and time the notes were made. |
| created_by | A foreign key to the doctor table for who created the notes. |
prescription
A record of a prescription made by a doctor for a patient.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| prescribed_appoint ment_id | A foreign key to the appointment where the prescription was made. |
| medicine_name | The name of the medicine that was prescribed. |
| dosage | The dosage of the medicine. |
| frequency | How often to take the medicine. |
| instructions | Special instructions for taking the medicine. |
| created_at | The date and time the notes were made. |
| created_by | A foreign key to the doctor table for who created the notes. |
| Learn how to design an effective database & create it with SQL | 5 |
patient_bill
A record of bills to be paid for by the patients.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| appointment_id | A foreign key to the appointment table, for the appointment for this bill. |
| amount | The amount of the bill. |
| bill_status_id | A foreign key to the bill_status table, to represent the status of the bill. |
| payment_method_id | A foreign key to the payment_method table, for the payment method used for this bill. |
| created_at | The date and time the record was created. |
| bill_paid_datetime | The date and time the bill was paid. |
payment_method
A lookup table for the payment methods.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| name | The name value of the payment method, such as Credit Card or Cash. |
bill_status
A lookup table for the bill status.
| Column | Description |
|---|---|
| id | Primary key. A unique identifier for the row. |
| name | The value of the bill status, such as Paid or Outstanding. |
| Learn how to design an effective database & create it with SQL | 6 |
SQL Script
Here is the SQL code to create the tables for this database.
The script is written for MySQL, but it can easily be modified to work on your preferred database vendor by changing the data types and removing the IF EXISTS (if your database doesn't support it).
1CREATE TABLE patient (
2 id integer PRIMARY KEY,
3 first_name varchar(255),
4 last_name varchar(255),
5 gender_id integer,
6 date_of_birth date,
7 phone_number varchar(255),
8 email_address varchar(255),
9 address_line1 varchar(255),
10 address_line2 varchar(255),
11 state varchar(255),
12 country_id integer,
13 created_at timestamp
14);
15
16CREATE TABLE country (
17 id integer PRIMARY KEY,
18 country_name varchar(255)
19);
20
21CREATE TABLE doctor (
22 id integer PRIMARY KEY,
23 first_name varchar(255),
24 last_name varchar(255),
25 gender_id integer,
26 created_at timestamp
27);
28
29CREATE TABLE gender (
30 id integer PRIMARY KEY,
31 name varchar(255)
32);
33
34CREATE TABLE specialisation (
35 id integer PRIMARY KEY,
36 name varchar(255)
37);
38
39CREATE TABLE doctor_specialisations (
40 doctor_id integer,
41 specialisation_id integer
42);
43
44CREATE TABLE appointment (
45 id intger PRIMARY KEY,
46 patient_id integer,
47 doctor_id integer,
48 appointment_datetime timestamp,
49 status_id integer,
50 reason varchar(255),
51 created_at timestamp
52);
53
54CREATE TABLE appointment_status (
55 id integer PRIMARY KEY,
56 name varchar(255)
57);
58
59CREATE TABLE appointment_note (
60 id integer PRIMARY KEY,
61 appointment_id integer,
62 notes text,
63 created_at timestamp,
64 created_by integer
65);
66
67CREATE TABLE prescription (
68 id integer PRIMARY KEY,
69 prescribed_appointment_id integer,
70 medicine_name varchar(255),
71 dosage varchar(255),
72 frequency varchar(255),
73 instructions varchar(255),
74 created_at timestamp,
75 created_by integer
76);
77
78CREATE TABLE patient_bill (
79 id integer PRIMARY KEY,
80 appointment_id integer,
81 amount decimal,
82 bill_status_id integer,
83 payment_method_id integer,
84 created_at timestamp,
85 bill_paid_datetime timestamp
86);
87
88CREATE TABLE payment_method (
89 id integer PRIMARY KEY,
90 name varchar(255)
91);
92
93CREATE TABLE bill_status (
94 id integer PRIMARY KEY,
95 name varchar(255)
96);
97ALTER TABLE patient ADD FOREIGN KEY (gender_id) REFERENCES gender (id);
98ALTER TABLE patient ADD FOREIGN KEY (country_id) REFERENCES country
99(id);
100ALTER TABLE doctor ADD FOREIGN KEY (gender_id) REFERENCES gender (id);
101ALTER TABLE doctor_specialisations ADD FOREIGN KEY (doctor_id)
102REFERENCES doctor (id);
103ALTER TABLE doctor_specialisations ADD FOREIGN KEY (specialisation_id)
104REFERENCES specialisation (id);
105ALTER TABLE appointment ADD FOREIGN KEY (patient_id) REFERENCES patient
106(id);
107ALTER TABLE appointment ADD FOREIGN KEY (doctor_id) REFERENCES doctor
108(id);
109ALTER TABLE appointment ADD FOREIGN KEY (status_id) REFERENCES
110appointment_status (id);
111ALTER TABLE appointment_note ADD FOREIGN KEY (appointment_id) REFERENCES
112appointment (id);
113ALTER TABLE appointment_note ADD FOREIGN KEY (created_by) REFERENCES
114doctor (id);
115ALTER TABLE prescription ADD FOREIGN KEY (prescribed_appointment_id)
116REFERENCES appointment (id);
117ALTER TABLE prescription ADD FOREIGN KEY (created_by) REFERENCES doctor
118(id);
119ALTER TABLE patient_bill ADD FOREIGN KEY (appointment_id) REFERENCES
120appointment (id);
121ALTER TABLE patient_bill ADD FOREIGN KEY (bill_status_id) REFERENCES
122bill_status (id);
123ALTER TABLE patient_bill ADD FOREIGN KEY (payment_method_id) REFERENCES
124payment_method (id);
Want to design a database from scratch?
Design Any Database in 60 Minutes is a 7-step framework that takes you from a real-world requirement to a working schema. You can get it here: Design Any Database.