HN Books @HNBooksMonth

The best books of Hacker News.

Hacker News Comments on
SQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers)

Bill Karwin · 6 HN comments
HN Books has aggregated all Hacker News stories and comments that mention "SQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers)" by Bill Karwin.
View on Amazon [↗]
HN Books may receive an affiliate commission when you make purchases on sites after clicking through links on this page.
Amazon Summary
Bill Karwin has helped thousands of people write better SQL and build stronger relational databases. Now he’s sharing his collection of antipatterns—the most common errors he’s identified in those thousands of requests for help. Each chapter in this book helps you identify, explain, and correct a unique and dangerous antipattern. The four parts of the book group the antipatterns in terms of logical database design, physical database design, queries, and application development. The chances are good that your application’s database layer already contains problems such as Index Shotgun, Keyless Entry, Fear of the Unknown, and Spaghetti Query. This book will help you and your team find them. Even better, it will also show you how to fix them, and how to avoid these and other problems in the future. SQL Antipatterns gives you a rare glimpse into an SQL expert’s playbook. Now you can stamp out these common database errors once and for all. Whatever platform or programming language you use, whether you’re a junior programmer or a Ph.D., SQL Antipatterns will show you how to design and build databases, how to write better database queries, and how to integrate SQL programming with your application like an expert. You’ll also learn the best and most current technology for full-text search, how to design code that is resistant to SQL injection attacks, and other techniques for success. Most developers aren’t SQL experts, and most of the SQL that gets used is inefficient, hard to maintain, and sometimes just plain wrong. This book shows you all the common mistakes, and then leads you through the best fixes. What’s more, it shows you what’s behind these fixes, so you’ll learn a lot about relational databases along the way.
HN Books Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this book.
- Bitemporal Databases: Modeling and Implementation: https://www.amazon.com/Bitemporal-Databases-Canan-Eren-Atay/...

- Developing Time-Oriented Database Applications in SQL by Rich. Snodgrass: https://www.amazon.com/Developing-Time-Oriented-Database-App...

-----

Anything by Joe Celko:

- SQL for Smarties: https://www.amazon.com/gp/product/B00R17NZZC

- SQL Programming Style: https://www.amazon.com/gp/product/B006L21AO6

- Trees and Hierarchies in SQL for Smarties: https://www.amazon.com/gp/product/B006Y8MKUU

- Thinking in Sets: https://www.amazon.com/gp/product/B001AODZZC

-------

- SQL Antipatterns by Bill Karwin: https://www.amazon.com/SQL-Antipatterns-Programming-Pragmati...

One of my favorite books to throw out for noobs is both a pattern and antipattern book for database folks. https://www.amazon.com/SQL-Antipatterns-Programming-Pragmati...
Not online, but SQL Antipatterns is the book that had the largest impact on my thinking:

https://www.amazon.com/SQL-Antipatterns-Programming-Pragmati...

But as you said, you haven't actively learned SQL, so probably need to find some free data sets to work with.

You can probably start with Data is Plural. That will, at least, give you some raw data sets so you can get started on learning how to build up a database from unorganized data first:

https://tinyletter.com/data-is-plural

Edit to add: First and foremost, you have to learn normalization. Without that, you aren't doing any SQL.

The relational model, by being based directly on set theory and first order logic, is the most robust method for managing data today.

Yes, SQL is not the best implementation; theoretically we could try out Tutorial D/D4/whatever, but it's good enough especially in the Postgres flavour which is built on decades of academic and commercial research. PostgreSQL is almost entirely declarative (the RM is declarative) - how do you propose to improve on that?

As a quick reminder, these are the things you have to build manually into your application if you're not using a relational DBMS (or check are included in your new black box solution for managing data):

- data being shared (concurrent access, writes, etc.);

- avoiding redundancy, inconsistency (which you get for free by centralising the data into a single copy instead of having one copy per thread/program/user);

- transaction (= logical unit of work) atomicity (all or nothing) - say you want to transfer money from A to B, decrease A, then increase B; what if "increase B" fails? A relational database will ensure your transaction does not half go through;

- integrity - impossible things are avoided by constraints, anything from "an employee logging 400 hours of work this week" to parsing different date formats (because the date is stored as string because it's an Entity Attribute Value antipattern because "the schema has to be flexible");

- easily enforced security ("nobody but finance accesses payroll tables");

- and obviously data independence, such as freedom from having to specify the physical representation of data and access techniques in your application code. (OK, this is one place where SQL is not perfect; but it's pretty good)

(*thanks to C. J. Date for the list)

The sad thing is that this stuff does not seem to be taught anymore; I get a lot of business from the fact that most frameworks encourage antipatterns by design (Bill Karwin's book on the subject [1] is a great, easy read for those who can't stomach C. J. Date's 1000 page "Introduction" [2]).

[1] http://www.amazon.com/SQL-Antipatterns-Programming-Pragmatic...

[2] http://www.amazon.com/Introduction-Database-Systems-8th/dp/0...

HN Books is an independent project and is not operated by Y Combinator or Amazon.com.
~ yaj@
;laksdfhjdhksalkfj more things
yahnd.com ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.