The books are academic and do not specify what to do with the foreign keys. For the college assignment I am building an SQL database for a dental clinic.
If I had to create foreign keys, do I need one per table or can a table specialist dental referral be left with no foreign key.
I have 5 tables in dental clinic database. appointment PK (primary key) app_id patient PK pat_id payment PK pay_id treatment PK treat_id referral PK ref_id
-- Constraints for table `appointment`
--
ALTER TABLE `appointment`
ADD CONSTRAINT `patient` FOREIGN KEY (`pat_id`) REFERENCES `patient` (`pat_id`),
ADD CONSTRAINT `pay_id` FOREIGN KEY (`pay_id`) REFERENCES `payment` (`pay_id`);
--
-- Constraints for table `patient`
--
ALTER TABLE `patient`
ADD CONSTRAINT `appointment` FOREIGN KEY (`app_id`) REFERENCES `appointment` (`app_id`),
ADD CONSTRAINT `ref` FOREIGN KEY (`ref_id`) REFERENCES `referral` (`ref_id`),
ADD CONSTRAINT `treat` FOREIGN KEY (`treat_id`) REFERENCES `treatment` (`treat_id`);
--
-- Constraints for table `payment`
--
ALTER TABLE `payment`
ADD CONSTRAINT `app` FOREIGN KEY (`app_id`) REFERENCES `appointment` (`app_id`),
ADD CONSTRAINT `pat` FOREIGN KEY (`pat_id`) REFERENCES `patient` (`pat_id`);
COMMIT;