O'Reilly logo

Joe Celko's Thinking in Sets: Auxiliary, Temporal, and Virtual Tables in SQL by Joe Celko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required