Change sql based on database schema