rebuild sql code