Sql reorg

Refactored most of the sql from the main specification to its own document. Ended up leaving table creation in the main spec, as it seemed useful to have a bit in there.