Fixed SQL build script. Now confirmed to work.
Stored procedures will be fixed later.