Wrapping up SQL

First wave of SQL should be ready for use in embedding within php, the
tables have been updated too