sql prototyper refactoring