I have 2 tables, that is
Patient Treatment
Datetime | Doctor | Patient | Complaint | Description | Medicine | Address |
---|---|---|---|---|---|---|
1/1/22 17:05 | Name A | Patient K | X | X | X | X |
1/1/22 17:11 | Name C | Patient L | X | X | X | X |
1/1/22 17:27 | Name B | Patient M | X | X | X | X |
1/1/22 17:41 | Name A | Patient N | X | X | X | X |
2/1/22 08:38 | Name A | Patient K | X | X | X | X |
Doctor Personal Data
Doctor | Specialist | Join Date | Degree | Hour Work | Phone Number | Address |
---|---|---|---|---|---|---|
Name A | X | X | X | X | X | X |
Name B | X | X | X | X | X | X |
Name C | X | X | X | X | X | X |
Name D | X | X | X | X | X | X |
I want to create a relation for both tables. The doctor's name in the Patient Treatment table refers to the doctor's name in Doctor Personal Data to retrieve the doctor's personal data. The Doctor Personal Data table has a unique column (name of doctor). However, I read in several questions on this stackexhange that the primary key being a string is not a good way to go because it's too slow. The two tables don't have an ID number like in most SQL tutorials. What is the best way to determine the primary key and foreign key for both tables?
This is my DDL query
CREATE TABLE `patient_treatment` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Datetime` timestamp NULL DEFAULT NULL,
`Doctor` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Patient` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Complaint` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Description` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Medicine` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Address` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
)
CREATE TABLE `doctor_personal_data` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`Doctor` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Specialist` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Join Date` timestamp NULL DEFAULT NULL,
`Degree` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Hour Work` timestamp NULL DEFAULT NULL,
`Phone Number` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`Address` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
)
ID
number fields.ID
field from one table to the other table to be your foreign key, like Niyaz's answer demonstrates.