I'm building a small application and setting up foreign key relationships between tables. However I'm confused as to WHY I really need this? What is the advantage - does it assist me when writing my queries that I don't have to perform any joins? Here's an example snippet of my database:
+-------------------+
| USERS |
+-------------------+
| user_id |
| username |
| create_date |
+-------------------+
+-------------------+
| PROJETS |
+-------------------+
| project_id |
| creator |
| name |
| description |
+-------------------+
There is a key relationship between users
.user_id
and projects
.creator
Would I be able to perform a query like so?
SELECT * FROM PROJECTS WHERE USERS.username = "a real user";
Since MySQL should know the relationship between the tables? If not then what is the real function of Foreign keys in a database design?