SQL_BASE refactor