Sql code for second entity