I Used My First Foreign Key

by stink on May 17, 2024 to sql comments(2)
I have been using SQL for 20 years as a full stack web developer. It's embarrassing to admit, but I have never used a foreign key in SQL. Until yesterday! I used a foreign key on this very site. In the comments database table there is a post_id that was previously just an integer but now it's a foreign key. When a post gets deleted all of its comments are automatically delete via the foreign key and there's no more need for the manual deletion of these comments. Here is the commit:

https://github.com/ferg1e/comment-castles/commit/b3c70b6d9b0ac1b3ad72a4aa469eb7c495a05ac2

Yay!