The application relates to the fields of
database management and
natural language processing, and specifically discloses a txt-to-
sql generation method based on
database sub-pattern division, which comprises the following steps: S1, constructing a
database graph; S2, performing sub-pattern division on a weighted
undirected graph G based on graph
cutting to obtain a plurality of subgraphs, each of which corresponds to a database sub-pattern; S3, generating a sub-pattern abstract; S4, adopting a two-stage matching mechanism to select the optimal sub-pattern most relevant to a
user input natural language query from a sub-pattern set; and S5, constructing a prompt word based on the optimal sub-pattern, the abstract corresponding to the optimal sub-pattern and the user
natural language query, and inputting the prompt word into a
large model to generate an
SQL query statement. The technical scheme provided by the application fuses a database
static structure and
dynamic query behavior, automatically divides high correlation sub-patterns, accurately locates relevant sub-patterns through a two-stage matching, greatly reduces the input complexity of the
large model, improves the accuracy and efficiency of
SQL generation, and is suitable for large-scale database scenes.