fix sql for getting foreignKeys