Obtain sql definitions under complex circumstances