SQL table creation, refactoring