To quote Mr Torvalds himself:
"Bad programmers worry about the code. Good programmers worry about data structures and their relationships."
Something that i struggled with before i learned how to use a SQL/relational database was to actualy use the database relations in my code. I first specified the relations in the database then i basicly redid them in the code.
The way i tend to program these days is to have basically all my relations restrictions and relational rules in the database. Whenever i want to change something you just alter stuff in the database GUI. Most of the application code will just follow along.