The invention discloses a method, device and equipment for generating an
SQL based on a
natural language and a storage medium, and relates to the technical field of
artificial intelligence and databases. The method comprises the following steps: firstly, establishing a
knowledge graph to clarify an incidence relation between an index and a
fact table and an incidence relation between the
fact table and a
dimension table, then identifying and locking a target
fact table through a target index, carrying out correlation retrieval to form a candidate
dimension table set, and analyzing and screening a step-by-step flow of the target
dimension table through
semantics and limitation conditions. The context input into the large
language model is always a minimum complete set related to query, the problem of
context window limitation caused by a full-scale table structure in a large-scale
database is effectively avoided, meanwhile, interference of irrelevant table structure information is reduced fundamentally, retrieval errors caused by same-name fields are avoided, and the retrieval efficiency is improved. The dimensionality semantic
ambiguity in the
natural language instruction is accurately solved, so that the generated
SQL statement can be accurately matched with the query intention of the user, and good performability is achieved.