Revert "SQL: Several Fixes"

This reverts commit 62054e924ac84faf524d4dbfded016577a42771e.