The invention discloses a multi-table combined
natural language query
SQL (structured
query language) generation method, which comprises the following steps of: 1, constructing a
database meta-
knowledge graph, and establishing a triple storage comprising a table structure, a primary and
foreign key relationship and business description for each data table; 2, receiving a
natural language query request, and calculating the topic relevancy between query
semantics and each
database table through a pre-trained topic matching model; 3, dynamically constructing a view, and logically associating the
database tables of which the theme relevancy exceeds a threshold value to form a temporary view; 4, generating a context enhancement prompt, and combining the temporary view structure, the field semantic description of the view and the view content sample to form a structured prompt; 5, inputting the
natural language query and the structured prompt into the large
language model to generate candidate
SQL statements; and step 6, executing
verification and iterative optimization on the candidate
SQL statements, verifying logic
correctness through SQL
execution plan analysis and result sampling, and triggering and prompting a reconstruction mechanism when detection is abnormal.