r/learnSQL • • 3d ago

Database design

Hey guys.

Gonna be real quick.

I know about databases but I struggle with database design either relational or non relational.

Do you have any resource that I can binge on and like solve this issue once and for all ?

Would appreciate it. Thanks in advance.

21 Upvotes

12 comments sorted by

17

u/nicopassaglia 3d ago • Bravo

Bingeing won't fix this one. Design is a skill you get by designing, getting it wrong and seeing why. What worked for me:

  1. Pick something real and small (a library, a repair shop, a gym). List the things it keeps track of and how they relate: one-to-many, many-to-many.
  2. Write the CREATE TABLE statements. Every many-to-many gets a link table.
  3. Attack your own design. Try to insert a duplicate, an order for a customer that doesn't exist, the same fact in two places. If the database lets you, the design has a hole.
  4. Write the five queries the business would ask every week. If one is painful, the tables are wrong.

For the theory behind it: "Database Design for Mere Mortals" (Hernandez) is the friendliest book, and Stanford's free Databases course by Jennifer Widom covers keys and normal forms properly. For non-relational it flips: you start from the queries you'll run and shape the data around them. "Designing Data-Intensive Applications" explains that part well.

Disclosure: I built getsheetdrill.com, which has lessons where you write the CREATE TABLE and it tests your tables with inserts that should be refused (keys, normalization, constraints). Those lessons are in the paid part; the query lessons are free.

1

u/TomWickerath 2d ago edited 2d ago

100% great answer!

I’ll add: 

     Columns are expensive / Rows are cheap 

Commit that to memory. If your design requires you to add new columns to accommodate similar data, then you likely have poor database normalization. A few examples would include ‘repeating groups of columns’, i.e. a column for each month or year:  Jan, Feb, Mar, etc. or 2025, 2026, 2027, etc.

A companion book, co-authored by Mike Hernandez and John Viescas, is also a good source of DB design information. The name of that book is “SQL Queries for Mere Mortals”. 

This web site has copies of two of Mike’s free papers:

https://www.accessmvp.com/JConrad/accessjunkie/resources.html#DatabaseDesign101

Database Design 101: Understanding Normalization by Michael Hernandez: ZIP File Download

Database Design Tips by Michael Hernandez: Database Design Tips.zip

One of them is only four pages, so a very easy read. The other one is some 21 (+/-) pages, and is A LOT more extensive. 

Some notable quotes from these two papers by Mike include:

“Always design on paper first …. You’d be surprised how fast an eraser works.”

and

“START WITH A NORMALIZED STRUCTURE! 'Nuff said.

The most important point for you to remember is that you will always re-introduce data integrity problems when you de-Normalize your structures! This means that it becomes incumbent upon you or the user to deal with this issue. Either way, it imposes an unnecessary burden upon the both of you. De-Normalization is one issue that you'll have to weigh and decide for yourself whether the perceived benefits are worth the extra effort it will take to maintain the database properly.”   .   . Note:  I think more recent editions of the book SQL Queries for Mere Mortals show only John’s name as the author, as Michael later pivoted his career from database design & .NET stuff to acting in Hollywood! Both Mike and John are personal acquaintances of mine as a former MS Access MVP awardee myself, and Mike was my guest speaker two times when I taught a part-time evening Database Design course in the early 2000’s at a community college.

3

u/Difficult_Paint3162 3d ago

I wrote this book a while back, free to download from syncfusion: Database Design Succinctly® | Free Ebook | Syncfusion®

It might give you some insight and ideas...

2

u/squadette23 3d ago

Try this and tell me if that is what you need: https://kb.databasedesignbook.com/posts/google-calendar/

"Database design" may mean a number of different things.

2

u/UnluckyManner9152 3d ago

One thing most tutorials skip: decide early what has to keep its history. A customer's address changes; should an old order show the old address or the new one? If the old one, the order needs its own copy, or the address needs dates. Many designs that look properly normalized break on that one question.

2

u/DataScientistAlex 3d ago

If you're thinking about organizing data for analytics, dimensional modeling might be useful.

2

u/No_Lawyer1947 3d ago

there is no resource i would recommend more than just makin some shit. Make an actual application where u are forced to solve the challenges relational and non relational db's solve.

1

u/jakingo 3d ago

Try designing databases for small real-world projects instead of watching tutorials. Start with entities, relationships, and constraints, then review your design as the requirements change.

1

u/Least_Ad_1795 2d ago

I’d recommend starting with database normalization, ER diagrams, relationships, and real-world schema design exercises. Practice designing databases for e-commerce, banking, and booking systems. Resources like Database Design for Mere Mortals and SQLBolt are good starting points. Focus more on building schemas for real-world problems than just watching tutorials.

1

u/Waste_Membership_483 2d ago

Conceptual to logical to physical model is quite a useful path 

1

u/titpetric 1d ago

Learning is a great resource, you solve parts of a problem and move on until it becomes a new problem