18.3. Data Constraint Approach

This method is due to Richard Romley. The idea is to UNION a SudokuGrid with the given digits to a constrained grid that has all the constraints imposed on each cell. The code gets a bit long, but it is repetitive and can be easily generated with a text editor. I will simply show the skeleton to save space.

But Richard also demonstrated another technique that makes many newbie SQL programmers nervous—long parameter lists.

CREATE PROCEDURE SolveSudoku (IN r1c1 INTEGER, IN r1c2 INTEGER, IN r1c3 INTEGER, IN r1c4 INTEGER, IN r1c5 INTEGER, IN r1c6 INTEGER, IN r1c7 INTEGER, IN r1c8 INTEGER, IN r1c9 INTEGER, .. IN r9c1 INTEGER, IN r9c2 INTEGER, IN r9c3 INTEGER, IN r9c4 INTEGER, IN r9c5 INTEGER, IN r9c6 INTEGER, IN r9c7 ...

Get Joe Celko's Thinking in Sets: Auxiliary, Temporal, and Virtual Tables in SQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.