Method and device for generating SQL statement

Through natural language description of business information, combining the generative model and historical SQL statement library, SQL statements are generated and selected, which solves the problems of cost and privacy protection of SQL statements, and improves efficiency and accuracy.

CN118916372APending Publication Date: 2024-11-08ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410919551.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

When using SQL statements, the syntax differences between different database types and data types lead to users having a certain amount of understanding and investment of time and energy. The accuracy of SQL statements generated by natural language and data privacy protection are an important technical challenge.

Method used

Describe business information through natural language, determine the candidate data table in the database, and use the pre-trained generative model and prompt information in the historical SQL statement library to generate and select target SQL statements through big model scoring.

Benefits of technology

It improves the business processing efficiency of the SQL language, saves user usage costs, improves user experience, and ensures the security of data privacy and the accuracy of statements through the use of open source models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916372A_ABST
    Figure CN118916372A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method and device for generating an SQL statement, and the method comprises the steps: determining a plurality of data tables in a database as candidate data tables according to description information which describes a current service through a natural language in a process of generating the SQL statement through natural language description information, the method comprises the steps that firstly, a plurality of candidate data tables and description information are obtained, then the candidate data tables and the description information are processed through a pre-trained generation model, a plurality of candidate SQL statements aiming at a current service are obtained, then prompt information obtained from a historical SQL statement library is utilized, the candidate SQL statements are scored through a large model, and therefore the SQL statement with the highest score is determined to serve as a target statement. According to the embodiment, the accuracy of the SQL statement generated by the natural language and the privacy of the data can be considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of computer technology, and in particular, to a method and apparatus for generating SQL statements. Background Art

[0002] SQL (Structured Query Language) is a "structured query language". It is an operating language for relational databases and can be applied to various relational databases. As a standard computer language for accessing and processing databases, SQL has specific syntax, data types, etc., and may have different syntaxes depending on the type of relational database. When using SQL statements, different database types and data types may have different operating effects using different syntaxes. In this way, in order to use the SQL language, users may need to have a certain understanding of the SQL language, the types of relational data tables, etc., that is, they need to invest corresponding time, energy and other costs. Using natural language to automatically generate SQL statements can save labor costs, improve the business processing efficiency of SQL language for relational databases, and improve user experience. In the process of automatically generating SQL statements using natural language, the accuracy of statement generation and the protection of data privacy are relatively important technical issues. Summary of the invention

[0003] One or more embodiments of this specification describe a method and device for generating SQL statements to solve one or more problems mentioned in the background technology.

[0004] According to a first aspect, a method for generating an SQL statement is provided, comprising: determining, based on first information describing a current business in a natural language, several data tables in a database as candidate data tables; processing each candidate data table and the first information through a pre-trained generation model to obtain multiple candidate SQL statements for the current business; using prompt information obtained from a historical SQL statement library, scoring each candidate SQL statement through a large model, thereby determining a target statement from each candidate SQL statement according to the scoring result.

[0005] In one embodiment, the candidate data table is determined from data tables to which the current user has access permissions.

[0006] In one embodiment, determining several data tables in a database as candidate data tables based on first information that describes the current business in natural language includes: extracting several keywords from the first information; matching each keyword with table information of each data table in the database; and determining candidate data tables from each data table according to the matching results.

[0007] In a further embodiment, the table information includes at least one of the following: data table name, primary key, foreign key, enumeration value, and is updated at a predetermined time interval.

[0008] In one embodiment, the processing of each candidate data table and the first information by a pre-trained generation model to obtain multiple candidate SQL statements for the current business includes: using each candidate data table and the first information as input data of the generation model, and generating multiple SQL statements by the generation model; verifying the validity of the multiple SQL statements; and determining the candidate SQL statements based on the verification results.

[0009] In a further embodiment, determining the candidate SQL statements based on the verification results includes: when each SQL statement passes the validity verification, determining the multiple SQL statements as candidate SQL statements; when each SQL statement does not completely pass the validity verification, regenerating multiple SQL statements through the generation model until each generated SQL statement passes the validity verification.

[0010] In one embodiment, a single historical SQL statement in the historical SQL statement library includes description information describing historical business and SQL statements used historically. The method of using the prompt information obtained from the historical SQL statement library to score each candidate SQL statement through a large model to determine the SQL statement with the highest score as the target statement includes: semantically matching the first information with the description information corresponding to each historical SQL statement in the historical SQL statement library to obtain each candidate historical SQL statement; using each candidate historical SQL statement as prompt information to score each candidate SQL statement through a large model to determine the target statement according to the output data of the large model.

[0011] According to a second aspect, there is provided a device for generating an SQL statement, comprising:

[0012] a determining unit configured to determine, based on the first information describing the current business in natural language, several data tables in the database as candidate data tables;

[0013] A generation unit, configured to process each candidate data table and the first information through a pre-trained generation model to obtain multiple candidate SQL statements for the current business;

[0014] The selection unit is configured to score each candidate SQL statement through a large model using prompt information obtained from a historical SQL statement library, thereby determining a target statement from each candidate SQL statement according to the scoring result.

[0015] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed in a computer, the computer is caused to execute the method of the first aspect.

[0016] According to a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein an executable code is stored in the memory, and when the processor executes the executable code, the method of the first aspect is implemented.

[0017] Through the method and device provided in the embodiments of this specification, in the process of generating SQL statements using natural language description information, several data tables in the database are determined as candidate data tables based on the description information of the current business described in natural language, and then each candidate data table and the description information are processed by a pre-trained generation model to obtain multiple candidate SQL statements for the current business. Then, using the prompt information obtained from the historical SQL statement library, each candidate SQL statement is scored through a large model, so that the target statement is determined from each candidate SQL statement according to the scoring results.

[0018] This implementation scheme brings better semantic understanding capabilities by introducing an open source large language model, and by combining professional database domain knowledge, the large language model has the ability to understand database-related knowledge. In addition, the large model is trained based on the open source model, and the data security of the entire process is controllable, avoiding the use of existing large models (closed source models) that can only use a large number of few shots (prompt information) to help the model understand the privacy leaks and other security risks. The design of generating candidate SQL statements and scoring candidate SQL statements separately, and introducing historical data in the process of scoring candidate SQL statements, can improve the accuracy of the target statement. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0020] Figure 1 It is a schematic diagram of the implementation scenario of generating SQL statements in this specification;

[0021] Figure 2 is a flowchart of generating SQL statements according to an embodiment of the present specification;

[0022] Figure 3 It is a schematic block diagram of an apparatus for generating SQL statements according to an embodiment of the present specification. DETAILED DESCRIPTION

[0023] The solution provided in this specification is described below in conjunction with the accompanying drawings.

[0024] SQL is a database language with multiple functions such as data operation and data definition. This language is interactive and can provide great convenience for users. Database management systems should make full use of SQL language to improve the work quality and efficiency of computer application systems. SQL language can not only be used independently in terminals, but also can be used as a sub-language to provide effective assistance for other program designs. For example, SQL can be used with other program languages ​​to optimize program functions, thereby providing users with more comprehensive information.

[0025] For example, the GroupBy statement can be used to group data in a SQL database according to certain rules. It can divide a data set into several small area data sets according to certain rules, and then perform data processing on the data sets in several small areas. Suppose that in a business processing process, it is necessary to determine the average leisure expenditure of employees under various working years. The data table is, for example, a SQL data table in the form shown in Table 1 below.

[0026] Table 1 Example of employee leisure expenditure data table

[0027] Id Outlay Age 1 1000 1 2 2000 1 3 3000 2 …… …… ……

[0028] During the business processing, the data needs to be grouped according to the years of work (Age), and the average of the leisure expenditure (Outlay) under each group needs to be calculated. For example, if the number of users with a working age of 1 is m, it is necessary to determine the user rows with a value of 1 in the "Working Age (Age)" field of the data table, and obtain the value of the "Leisure Expenditure (Outlay)" field from these rows, and calculate the average of them, such as (1000+2000+…) / m. In SQL business processing, this business can be implemented, for example, through the "groupby" statement, such as "Select age, avg (Outlay) from table 1 group by age".

[0029] In actual business, if you are not familiar with SQL syntax or existing data tables, generating professional SQL statements may require additional manpower, resources and other costs. Therefore, this specification provides a technical solution for generating SQL statements based on natural language description information. Figure 1As shown, for the business description information described in natural language input by the user to the computing platform, the relevant data table can be identified and matched from the database as a candidate data table, and an SQL statement output can be generated according to the business description information and the candidate data table. Under the technical concept of this specification, multiple candidate statements in the SQL language can be generated according to the logical reasoning of business needs, and then the historical SQL statements are used as prompt words to select one from multiple candidate statements through a large model. The selected SQL statement can be used directly for business processing or pushed to the user. In this way, the user's cost of using the SQL language can be saved, and the user experience and business processing efficiency can be improved.

[0030] A large model, or Large Language Model (LLM), is a pre-trained artificial intelligence model designed to understand and generate human language. Large models are often trained on large text corpora and can perform a wide range of tasks, including text summarization, translation, sentiment analysis, and so on. LLMs are usually large in scale, contain billions of parameters, and can learn complex patterns in language data. These models are usually based on deep learning architectures, such as transformers, which help achieve better results in various natural language processing (NLP) tasks. The introduction of large models, on the one hand, makes the processing of semantic information more efficient, and on the other hand, the use of closed-source large models may pose the risk of leaking database privacy through prompt information.

[0031] In view of this, the technical solution for generating SQL statements based on natural language description information provided in this specification is based on an open source big model and effectively protects data privacy. Generating SQL statements and determining target statements from the generated SQL statements using historical data are performed separately, which can ensure the accuracy of the determined target statements.

[0032] Combine the following Figure 2 The technical concept of this specification is introduced in detail.

[0033] Figure 2 The process of generating SQL statements according to an embodiment is shown. The execution subject of the process of generating SQL statements can be any computer, device, server, etc. with certain computing capabilities. As a specific example, Figure 1 computing platform (such as a server that provides corresponding business support to users).

[0034] like Figure 2 As shown, the process of generating SQL statements provided by one embodiment of this specification may include the following steps:

[0035] Step 210, obtaining each candidate data table according to the first information describing the current business in natural language; Step 220, processing each candidate data table and the first information through a pre-trained generation model to obtain multiple candidate SQL statements for the current business; Step 230, using the prompt information obtained from the historical SQL statement library, scoring each candidate SQL statement through a large model, thereby determining the target statement from each candidate SQL statement according to the scoring result.

[0036] First, through step 210, various candidate data tables are determined according to first information describing the current business in natural language.

[0037] Here, the current business is any business involving access to a data table, such as the business of finding the average value according to a certain field mentioned above. The first information is information that describes the business requirements of the current business in natural language, where "first" is for the convenience of description and does not substantially limit the corresponding information. Taking the business of finding the average value according to a certain field mentioned above as an example, the first information can be, for example, "calculating the average value of leisure expenditure of employees of the company".

[0038] Through the first information, several related data tables in the database can be determined as candidate data tables. Figure 1 As shown, the database can be set in the execution subject of the current process, or in other devices external to the execution subject, which is not limited here.

[0039] In one embodiment, all data tables in the database may be obtained as candidate data tables.

[0040] In another embodiment, the access rights of the current user can be determined, and data tables in the database can be obtained as candidate data tables within the scope of the user's access rights. For example, the access rights of ordinary employees are relatively small basic information data tables such as the company's employees' positions, expected attendance time, actual attendance time, responsible projects, contact numbers, etc. On this basis, employees in the human resources department can also access data tables of further private information such as employees' years of work, salary, identity code, address, physical examination results, etc.

[0041] In another embodiment, a data table associated with the first information can be obtained as a candidate data table. Specifically, keywords can be extracted from the first information, the extracted keywords can be matched with the table information of each data table, and several data tables can be selected from each data table as candidate data tables according to the matching results. Among them, the process of extracting keywords from the first information is, for example, segmenting the first information, removing stop words, etc., and retaining the words as keywords. For example, the keywords extracted from the first information "Statistics of the average leisure expenditure of employees of this company" are: statistics, this company, employees of this company, leisure, expenditure, leisure expenditure, average. The table information can be pre-cleaned and stored data describing the data table, such as the data table name, primary key, foreign key, enumeration value (the value that needs to be explicitly specified by enumeration when creating the table, such as the fields identifying male and female corresponding to the specified values ​​0, 1, etc.). In actual business, the table information may change dynamically in real time, so it can be cleaned and updated at predetermined time intervals (such as one day, one week, etc.). Table information cleaning methods include, for example, extracting keywords, extracting primary keys, foreign keys, table fields, etc., which are not described here. A single data table can correspond to a piece of table information. The process of matching the keywords extracted from the first information with the table information of each data table can adopt vocabulary matching or semantic vector matching, which is not limited here.

[0042] In other embodiments, the candidate data table may be determined by other reasonable methods, such as selecting a data table matching the first information from the data tables within the user's access rights as the candidate data table, which will not be listed here one by one.

[0043] In a possible design, the process of determining the candidate data tables can be implemented via a large model. In the process of determining the candidate data tables, the first information and the table information of each data table in the database can be used as prompt information, and the task description can be performed in natural language (such as selecting several data tables with a high degree of matching with the first information from each data table), and the large model can perform corresponding identification and processing, thereby outputting one or more data tables as candidate data tables.

[0044] Next, in step 220, a plurality of candidate data tables and the first information are processed by a pre-trained generation model to obtain a plurality of candidate SQL statements for the current business.

[0045] The generative model here can be various language processing models related to language processing, for example, models implemented by fully connected networks, attention mechanisms, etc. The training samples of the generative model can include business information described in natural language as feature data, candidate data tables, etc., and SQL statements as label data. At this time, the generative model can be trained in a supervised model training manner.

[0046] In an optional embodiment, the generation model can be implemented via a large model. Those skilled in the art will appreciate that there are generally two ways to apply a large model. One is to fine-tune the parameters of the large model through a small number of training samples so that the large model can adapt to the current SQL statement generation task. The other is to call the large model to generate SQL statements by using business description information, candidate data tables, and a small number of samples as prompt information. This specification does not limit the application of the generation model as a large model.

[0047] It can be understood that the generation model usually tends to logical reasoning, that is, according to the table information of the candidate data table and the user's description information of the business (such as the first information), the data table access processing logic is analyzed and implemented as an SQL statement via SQL syntax. For the current business, the generation model can generate one or more SQL statements.

[0048] It is understandable that the table information of the data table can be asynchronously updated at a predetermined time interval (such as 1 day). Therefore, when the user enters the description information of the current business, there may be incremental table data that has not been cleaned. Therefore, in some optional implementations, the data processed by the generation model includes not only multiple candidate data tables and the first information, but also the incremental data in the table information. In the case where the generation model is a large model, these incremental data can be used as prompt information together with the candidate data table and the first information as prompt information, and the large model is used to generate candidate SQL statements.

[0049] According to a possible design, the validity of the generated SQL statements can also be verified, and candidate SQL statements can be determined based on the validity verification results. It can be understood that for SQL statements, the syntax must be correct first before they can be successfully executed. Therefore, validity verification can include correctness verification, such as syntax correctness. In addition, some SQL statements may also have the problem of low execution efficiency. In this case, validity verification can also include verification of execution efficiency. Furthermore, when each SQL statement passes the validity verification, the currently generated SQL statement can be determined as a candidate SQL statement; conversely, when each SQL statement does not completely pass the validity verification, multiple SQL statements can be regenerated through the generation model until each generated SQL statement passes the validity verification.

[0050] Then, through step 230, the prompt information obtained from the historical SQL statement library is used to score each candidate SQL statement through the large model, so as to determine the target statement from each candidate SQL statement according to the scoring result.

[0051] The historical SQL statement library corresponds to the SQL statements generated or used in the history, which are generated by describing the corresponding historical business in natural language. Statements with description information similar to the first information semantics can be selected from the historical SQL statements as prompt information of the big model, and the big model scores each candidate SQL statement with reference to the historical SQL statements.

[0052] The selection of statements whose description information is semantically similar to the first information from the historical SQL statements can be performed by semantically matching the first information with each historical SQL statement. In one embodiment, the description information corresponding to each historical SQL statement can be segmented, and a keyword set can be obtained therefrom, and the keyword set obtained by segmenting the first information can be used to perform vocabulary matching with the keyword set of each historical SQL statement, and the corresponding matching degree can be measured by an indicator such as the Jaccard coefficient. In another embodiment, the first semantic vector corresponding to the first information can be determined, and the first semantic vector can be matched with each semantic vector corresponding to each historical SQL statement, and the corresponding matching degree can be measured by an indicator such as the cosine coefficient, cross entropy, and Euclidean distance. In other embodiments, the semantic vectors corresponding to the first information and each historical SQL statement can be matched by other methods. Furthermore, one or more historical SQL statements whose matching degree with the first information is ranked top from high to low can be selected from the historical SQL statement library as prompt information.

[0053] It can be understood that the historical SQL statements not only contain the description information of the business requirements in natural language, but also contain the verified correct SQL statements corresponding to the description information. Therefore, it can provide a reference for the association between the description information and the SQL statements. Using the historical SQL statements as prompt information, the big model can predict the correlation between the first information for the current business and each candidate SQL statement. The correlation can be quantified into a numerical form for evaluating each candidate SQL statement. The obtained numerical value is the scoring result of each candidate SQL statement. According to the order of the scores from high to low, the order of relevance to the first information from high to low can be determined, so that one or more SQL statements with a high correlation can be selected as the SQL statement generated for the first information, that is, the target statement. Optionally, a SQL statement with the highest correlation can be selected as the target statement. The output data of the big model can be the scoring scores of each candidate SQL statement, or it can be a target statement, which is not limited here.

[0054] Looking back at the above process, in the process of generating SQL statements using natural language description information, according to the first information describing the current business through natural language, several data tables in the database are determined as candidate data tables, and then the pre-trained generation model is used to process each candidate data table and the first information to obtain multiple candidate SQL statements for the current business, and then the prompt information obtained from the historical SQL statement library is used to score each candidate SQL statement through the large model, so as to determine the target statement from the candidate SQL statements according to the scoring results. This implementation scheme brings better semantic understanding ability by introducing a large language model, and can enable the large language model to have database-related knowledge understanding ability by combining professional database domain knowledge. The large model is trained on corpus based on the open source model, and the security of the entire process is controllable, avoiding the privacy leakage security risks caused by the use of existing large models (closed source models) that can only help the model understand through a large number of few shots (prompt information). In addition, the design of generating candidate SQL statements and scoring candidate SQL statements, introducing historical data in the process of scoring candidate SQL statements, can also improve the accuracy of the target statement.

[0055] Experiments show that the SQL generation process in the embodiment provided in this specification is slightly less accurate than the more mature closed-source large model (such as GPT-4, etc.) solution based on a large number of Few-shots, and is higher than multiple other closed-source large models and other solutions using open-source large models. Refer to Table 1, where the bold SQLfuse in the Solution field is the technical solution provided in this specification.

[0056] Table 1 Comparison of SQL generation effects of various large models

[0057] Rank. Solution TESTAcc Type LLM 1. MiniSeek 91.2 Unknown Unknown 2. DAIL-SQL+GPT-4+Self-Consistency[9] 86.6 Prompting Closed source 3. DAIL-SQL+GPT-4[9] 86.2 Prompting Closed source 4. SQLfuse 85.6 Fine-tuning open source 5. DPG-SQL+GPT-4+Self-Correction 85.6 Prompting Closedsource 6. DIN-SQL+GPT-4

[29] 85.3 Prompting Closed source 7. Hindsight Chain ofThought with GPT-4 83.9 Prompting Closed source 8. C3+ChatGPT+Zero-Shot[8] 82.3 Prompting Closedsource 9. Hindsight ChainofThought with GPT-4 and Instructions 80.8 Prompting Closedsource 10. RESDSQL-3B+NatSQL

[16] 79.9 Fine-tuning open source

[0058] As can be seen from Table 1, the technical solution provided in this specification strikes a good balance between prediction accuracy based on large models and data privacy.

[0059] According to another embodiment, a device for generating SQL statements is also provided. The device for generating SQL statements can be set in any computer, device, or server with certain computing capabilities. Figure 3 FIG. 4 shows a structural block diagram of a device for generating SQL statements according to an embodiment. Figure 3 As shown, the device 300 for generating SQL statements may include:

[0060] A determination unit 31 is configured to determine, based on the first information describing the current business in a natural language, several data tables in the database as candidate data tables;

[0061] A generating unit 32 is configured to process each candidate data table and the first information through a pre-trained generating model to obtain a plurality of candidate SQL statements for the current business;

[0062] The selection unit 33 is configured to score each candidate SQL statement through a large model using the prompt information obtained from the historical SQL statement library, thereby determining a target statement from each candidate SQL statement according to the scoring result.

[0063] In one embodiment, the candidate data table may be determined from data tables to which the current user has access permissions.

[0064] According to some optional implementation methods, the determination unit 31 can be configured to determine that several data tables in the database are candidate data tables in the following manner: extract several keywords from the first information; match each keyword with the table information of each data table in the database; and determine the candidate data table from each data table according to the matching results.

[0065] The table information includes at least one of the following: data table name, primary key, foreign key, and enumeration value. In addition, the table information can be updated at a predetermined time interval.

[0066] In a possible design, the determination unit 31 may also be configured to: use each candidate data table and the first information as input data of a generation model, and generate multiple SQL statements by the generation model; verify the validity of the multiple SQL statements; and determine the candidate SQL statements based on the verification results.

[0067] Among them, the determination unit 31 can be configured to determine the candidate SQL statements in the following manner: when each SQL statement passes the validity verification, multiple SQL statements are determined as candidate SQL statements; when each SQL statement does not completely pass the validity verification, multiple SQL statements are regenerated through the generation model until each generated SQL statement passes the validity verification.

[0068] In an optional embodiment, a single historical SQL statement in the historical SQL statement library may include description information describing historical business and historically used SQL statements. The selection unit 33 may be further configured to: semantically match the first information with the description information corresponding to each historical SQL statement in the historical SQL statement library to obtain each candidate historical SQL statement; use each candidate historical SQL statement as prompt information, and score each candidate SQL statement through the big model to determine the target statement according to the output data of the big model.

[0069] It is worth mentioning that Figure 3 The device 300 shown is Figure 2 The illustrated method embodiment corresponds, therefore,Figure 2 The corresponding description in the method embodiment also applies to Figure 3 The device 300 shown is not described in detail here.

[0070] According to another embodiment, there is also provided a computer readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute a combination of Figure 2 The method described by et al.

[0071] According to another embodiment of the present invention, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the Figure 2 The method described by et al.

[0072] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of this specification can be implemented by hardware, software, firmware, or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.

[0073] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of the technical concept of this specification. It should be understood that the above description is only the specific implementation method of the technical concept of this specification, and is not used to limit the protection scope of the technical concept of this specification. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the embodiments of this specification should be included in the protection scope of the technical concept of this specification.

Claims

1. A method for generating an SQL statement, comprising: According to the first information describing the current business in natural language, determining several data tables in the database as candidate data tables; Processing each candidate data table and the first information through a pre-trained generation model to obtain multiple candidate SQL statements for the current business; Using the prompt information obtained from the historical SQL statement library, each candidate SQL statement is scored through a large model, and the target statement is determined from each candidate SQL statement based on the scoring result.

2. The method of claim 1, wherein: The candidate data table is determined from the data tables to which the current user has access rights.

3. The method of claim 1, wherein: The step of determining, according to the first information describing the current business in natural language, several data tables in the database as candidate data tables comprises: extracting a number of keywords from the first information; Match each keyword with the table information of each data table in the database; A candidate data table is determined from each data table according to the matching result.

4. The method of claim 3, wherein: The table information includes at least one of the following: data table name, primary key, foreign key, enumeration value, and is updated at a predetermined time interval.

5. The method of claim 1, wherein: The pre-trained generation model is used to process each candidate data table and the first information to obtain multiple candidate SQL statements for the current business, including: Using each candidate data table and the first information as input data of the generation model, and generating multiple SQL statements by the generation model; Verifying the validity of the multiple SQL statements; Determine candidate SQL statements based on the verification results.

6. The method of claim 5, wherein: Determining the candidate SQL statement according to the verification result includes: When each SQL statement passes the validity verification, the multiple SQL statements are determined as candidate SQL statements; In the case that each SQL statement fails to completely pass the validity verification, multiple SQL statements are regenerated by the generation model until each generated SQL statement passes the validity verification.

7. The method of claim 1, wherein: A single historical SQL statement in the historical SQL statement library includes description information describing historical business and historically used SQL statements. The method of using the prompt information obtained from the historical SQL statement library to score each candidate SQL statement through a large model, thereby determining the SQL statement with the highest score as the target statement includes: semantically matching the first information with the description information corresponding to each historical SQL statement in the historical SQL statement library to obtain each candidate historical SQL statement; Each candidate historical SQL statement is used as prompt information, and each candidate SQL statement is scored through the big model to determine the target statement according to the output data of the big model.

8. A device for generating SQL statements, comprising: a determining unit configured to determine, based on the first information describing the current business in natural language, several data tables in the database as candidate data tables; A generation unit, configured to process each candidate data table and the first information through a pre-trained generation model to obtain multiple candidate SQL statements for the current business; The selection unit is configured to use the prompt information obtained from the historical SQL statement library to score each candidate SQL statement through a large model, so as to determine the target statement from each candidate SQL statement according to the scoring result.

9. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 7.

10. A computing device comprising a memory and a processor, characterized in that: The memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 7 is implemented.