refactor createTableQuery