SQL statement generation method and device, electronic equipment and storage medium

By obtaining natural language target statements, determining data table association information and generating prompt words, the efficiency of SQL statement generation in a multi-table environment is solved, and the generation quality and query efficiency of SQL statements are improved.

CN119311716APending Publication Date: 2025-01-14PEOPLE'S INSURANCE COMPANY OF CHINA
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411412195.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-10
Publication Date
2025-01-14

AI Technical Summary

Technical Problem

In a multi-table environment, automatically generating accurate SQL statements to meet query needs is a challenge, affecting data processing efficiency.

Method used

By obtaining target statements in natural language, determining multiple target data tables associated with them, obtaining association information from the table relation knowledge base, generating prompt words and inputting large models to generate high-quality SQL statements, reducing the computational volume of large models. Improve the quality of SQL statement generation for multi-table association.

Benefits of technology

By providing table structure information and association information, we help big models generate high-quality SQL statements, which improves the generation quality of SQL statements with multi-table associations, reduces the amount of calculation, and improves query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311716A_ABST
    Figure CN119311716A_ABST
Patent Text Reader

Abstract

The invention provides an SQL statement generation method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining a target statement used for operating a database; wherein the target statement is a natural language statement; determining a plurality of target data tables associated with the target statement in a database; obtaining association information among the plurality of target data tables from a table relationship knowledge base; generating a first cue word according to the target statement, the structure information of each target data table and the associated information; and inputting the first cue word into the large model to obtain an SQL statement generated by the large model. According to the method, the cue word is generated according to the target statement in combination with the association information among the target data tables and the table structure information of the data tables, so that the table structure information, the table association information and the like can be provided for the large model, and the large model generates the high-quality SQL statement based on the table structure information, the table association information and the like; and the generation quality of the multi-table associated SQL statement is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for generating an SQL statement. Background Art

[0002] With the rapid development of database technology, data organization and management have become increasingly complex. In a multi-table environment, automatically generating accurate SQL statements to meet query requirements is the key to improving data processing efficiency. Summary of the invention

[0003] The present application aims to solve one of the technical problems in the related art at least to some extent.

[0004] To this end, the first purpose of the present application is to propose a method for generating SQL statements to achieve the generation of high-quality SQL statements.

[0005] The second objective of the present application is to provide a device for generating SQL statements.

[0006] The third objective of the present application is to provide an electronic device.

[0007] A fourth objective of the present application is to provide a computer-readable storage medium.

[0008] A fifth object of the present application is to provide a computer program product.

[0009] To achieve the above-mentioned purpose, the first embodiment of the present application proposes a method for generating an SQL statement, comprising:

[0010] Acquire a target sentence for operating a database; wherein the target sentence is a natural language sentence;

[0011] Determining a plurality of target data tables associated with the target statement in a database;

[0012] Acquire association information between the multiple target data tables from a table relationship knowledge base;

[0013] Generate a first prompt word according to the target sentence, the structural information of each target data table and the associated information;

[0014] The first prompt word is input into the big model to obtain the SQL statement generated by the big model.

[0015] To achieve the above-mentioned purpose, the second embodiment of the present application proposes a device for generating SQL statements, including:

[0016] A first acquisition module is used to acquire a target sentence for operating a database; wherein the target sentence is a natural language sentence;

[0017] A determination module, used for determining a plurality of target data tables associated with the target statement in a database;

[0018] A second acquisition module, used for acquiring association information between the plurality of target data tables from a table relationship knowledge base;

[0019] A generating module, configured to generate a first prompt word according to the target sentence, the structural information of each target data table and the associated information;

[0020] The third acquisition module is used to input the first prompt word into the large model to obtain the SQL statement generated by the large model.

[0021] To achieve the above-mentioned purpose, the third aspect of the present application provides an electronic device, including:

[0022] A processor, and a memory communicatively connected to the processor;

[0023] The memory stores computer-executable instructions;

[0024] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect embodiment above.

[0025] To achieve the above-mentioned purpose, the fourth aspect embodiment of the present application proposes a computer-readable storage medium, in which computer execution instructions are stored. When the computer execution instructions are executed by a processor, they are used to implement the method described in the first aspect embodiment above.

[0026] To achieve the above-mentioned purpose, the fifth aspect of the present application proposes a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.

[0027] The SQL statement generation method, device, electronic device and storage medium provided in the present application can reduce the calculation amount of the large model by determining multiple target data tables associated with the target statement in the database and generating SQL statements based on the target data tables. According to the target statement, prompt words are generated in combination with the association information between the multiple target data tables and the table structure information of the data tables, so that the table structure information, table association information, etc. can be provided for the large model. Therefore, the large model generates high-quality SQL statements based on the table structure information, table association information, etc., thereby improving the generation quality of SQL statements associated with multiple tables.

[0028] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0030] Figure 1 A flowchart of a method for generating a SQL statement provided in an embodiment of the present application;

[0031] Figure 2 A flowchart of another method for generating a SQL statement provided in an embodiment of the present application;

[0032] Figure 3 A flowchart of another method for generating a SQL statement provided in an embodiment of the present application;

[0033] Figure 4 A schematic diagram of the structure of a device for generating SQL statements provided in an embodiment of the present application. DETAILED DESCRIPTION

[0034] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.

[0035] The following describes the method and device for generating SQL statements according to the embodiments of the present application with reference to the accompanying drawings.

[0036] Figure 1 A flowchart of a method for generating a SQL statement provided in an embodiment of the present application.

[0037] like Figure 1 As shown, the method for generating the SQL statement includes the following steps:

[0038] Step 101: Obtain a target statement for operating a database.

[0039] Among them, the target sentence is a natural language sentence, that is, the target sentence is a sentence in natural language form.

[0040] In this application, the user can enter a target statement in the data query interface. For example, the user enters the target statement: query the names of all users with the user administrator position in Province A.

[0041] Step 102: determine multiple target data tables associated with the target statement in the database.

[0042] In the present application, since the database may include multiple data tables, multiple data tables associated with the target sentence in the database may be determined.

[0043] Exemplarily, keyword recognition may be performed on the target sentence to determine the keywords in the target sentence, and the keywords may be matched with the table names of the data tables in the database. The data table in the database whose table name matches the keywords may be determined as the target data table.

[0044] Step 103: Acquire association information between multiple target data tables from a table relationship knowledge base.

[0045] In this application, the association relationships between data tables can be divided into three categories for management, namely, association types, foreign key constraints, and joint query fields. Based on this, a table relationship knowledge base can be pre-built, which may include but is not limited to association types between data tables, configured foreign key associations, typical joint query fields, etc.

[0046] The association types between data tables can be divided into one-to-one, one-to-many, and many-to-many for configuration and maintenance. The configuration examples of association types are as described in Table 1 below:

[0047] Table 1

[0048] Data Table 1 Data Table 2 Relationship User Fwptcompany One-to-one User UserGrade (user position) Many-to-Many Category Func (Functional Permissions) One-to-many

[0049] Among them, the association relationship is the joint query field, which refers to which fields are used to associate between two data tables, and the connection method used by the associated fields. The configuration example of the joint query field is shown in Table 2 below:

[0050] Table 2

[0051] Data Table 1 Data Table 2 Relation fields Connection User Fwptcompany Comcode Inner Join User UserGrade Userid Inner Join Category Func Cataid Left Join

[0052] It can be seen that in the above Table 2, the association field between the data table User and the data table Fwptcompany is Comcode, and the connection method is inner join; the association field between the data table User and the data table UserGrade is Userid, and the connection method is inner join; the association field between the data table Category and the data table Func is Cataid, and the connection method is left join.

[0053] In the present application, association information between multiple data tables can be obtained from a table relationship knowledge base according to the table name of each target data table.

[0054] The association information may include, but is not limited to, the association type between target data tables, foreign key constraint information, connection fields between target data tables, connection methods of connection fields, etc.

[0055] Step 104: Generate a first prompt word according to the target sentence, the structural information of each target data table and the associated information.

[0056] The structural information of the target data table may include information such as the column names of the target data table and the column descriptions corresponding to the column names.

[0057] Exemplarily, the structural information of the target data table can be obtained based on the data table metadata configuration. The data table metadata configuration can refer to the configuration of the function of the data table and the data content description stored in the columns. For example, the data table configuration example is shown in Table 3 below, and the column configuration of the data table is shown in Table 4 below:

[0058] Table 3

[0059] Table name Table Description User User Information Table Fwptcompany Institution Information Form

[0060] Table 4

[0061] Table name Column Name Column Description User username User Name User Comcode Institution Code Fwptcompany Comcode Institution Code Fwptcompany Comname Institution Name

[0062] In the present application, a prompt word can be constructed according to the target statement, the structural information of each target data table and the associated information to generate a first prompt word, wherein the first prompt word can be used to prompt the large model to execute the SQL statement generation task.

[0063] For example, if the target statement entered by the user is "Query the names of all users with the user administrator position in province A", the first prompt word can be as follows:

[0064] The existing user query requirements are as follows: Please generate an SQL statement for "querying the names of all users with user administrator positions in Province A". The data tables involved are user, fwptcompany, and UserGrade. The table structures are: use r(useid(user id), comcode(affiliation code), usename(user name)), fwptcompany(comcode(institution code), comname(institution name)), UserGrade(useid(user id), grade(position name)). Among them, user and fwptcompany use inner joins, and the join field is comcode. User and UserGrade are inner joins, and the join field is Userid. There is no foreign key constraint between the tables.

[0065] Step 105: input the first prompt word into the large model to obtain the SQL statement generated by the large model.

[0066] In the present application, the first prompt word may be input into the large model, and the large model processes the first prompt word and outputs a generated SQL statement.

[0067] For example, if the target statement is "query the names of all users with the user administrator position in province A", the output of the large model can be as follows:

[0068] To generate a SQL query statement that meets your requirements, you can use the following SQL code:

[0069] SELECT u.usename AS username

[0070] FROM user u

[0071] JOIN fwptcompany c ON u.comcode=c.comcode

[0072] JOIN UserGrade ug ON u.useid=ug.useid

[0073] WHERE ug.grade = 'User Administrator'

[0074] and comname = 'Province A'

[0075] In an embodiment of the present application, by determining multiple target data tables associated with the target statement in the database, generating SQL statements based on the target data tables can reduce the amount of calculation of the large model. According to the target statement, prompt words are generated in combination with the association information between the multiple target data tables and the table structure information of the data tables, so that the table structure information, table association information, etc. can be provided for the large model. As a result, the large model generates high-quality SQL statements based on the table structure information, table association information, etc., thereby improving the generation quality of SQL statements associated with multiple tables.

[0076] Figure 2 A flowchart of another method for generating SQL statements provided in an embodiment of the present application.

[0077] like Figure 2 As shown, the method for generating the SQL statement may include the following steps:

[0078] Step 201: Obtain a target statement for operating a database.

[0079] In the present application, step 201 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0080] Step 202: determine multiple target data tables associated with the target statement in the database.

[0081] In the present application, step 202 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0082] Step 203: Acquire association information between multiple target data tables from a table relationship knowledge base.

[0083] In the present application, step 203 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0084] Step 204: parse the target data table to determine the data volume and index information of the target data table.

[0085] In the present application, the target data table can be parsed by executing a data volume query command to determine the data volume of the target data table, wherein the data volume of the target data table can refer to the number of data items in the target data table.

[0086] In this application, the index information of the target data table can be obtained by executing the index query command. For example, in MySQL, the SHOW INDEX command can be executed to obtain the index information of the target data table, and in PostgreSQL, the \di command can be used to obtain the index information of the target data table.

[0087] The index information may refer to the fields on which the index is built. For example, the index information of the organization information table fwptcomany is that an index is built on the organization code comcode field.

[0088] Step 205: Generate a first prompt word according to the target sentence, structure information, association information, data volume corresponding to the target data table, and index information.

[0089] For example, the prompt word can be constructed according to the target sentence, the structure information of multiple target data tables, the association information between multiple data tables, the data volume and index information corresponding to each target data table, and the corresponding prompt word template to obtain the first prompt word. It can be seen that the first prompt word includes not only the table structure information and the table association information, but also the data volume and index information of the data table, which enriches the content of the prompt word.

[0090] For example, if the target statement entered by the user is "Query the names of all users with the user administrator position in province A", the first prompt word can be as follows:

[0091] The existing user query requirements are as follows: Please generate an SQL statement for "querying the names of all users with user administrator positions in Province A". The data tables involved are the user table, fwptcompany table, and UserGrade table. The table structures are: use r(useid(user id), comcode(affiliation code), usename(user name)), fwptcompany(comcode(institution code), comname(institution name)), UserGrade(useid(user id), grade(position name)). Among them, user and fwptcompany use inner joins, and the connection field is comcode. User and UserGrade are inner joins, and the connection field is Userid. There are no foreign key constraints between the tables. To ensure the query efficiency of the generated SQL, please consider the following data volume and index factors: the fwptcomany table has 100,000 data items, and an index is built on the comcode field; the user table has 80,000 data items, and an index is built on the userid field; the usergrade table has 90,000 data items, and a joint index is built on the userid and grade fields.

[0092] Step 206: input the first prompt word into the big model to obtain the SQL statement generated by the big model.

[0093] In the present application, step 206 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0094] In an embodiment of the present application, the target data table can be parsed to determine the data volume and index information of the target data table, and the data volume and index information of the data table are supplemented in the prompt words input into the big model for generating SQL statements. Therefore, by understanding the data volume of the data table, the big model can better understand the scale and complexity of the query, which helps the model to consider performance factors when generating SQL statements. The index information can guide the big model to generate more effective SQL statements, thereby significantly improving the accuracy of the SQL statements generated by the big model and improving the query efficiency of the SQL statements.

[0095] Figure 3 A flowchart of another method for generating SQL statements provided in an embodiment of the present application.

[0096] like Figure 3 As shown, the method for generating the SQL statement may include the following steps:

[0097] Step 301: Obtain a target statement for operating a database.

[0098] In the present application, step 301 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0099] Step 302: determine multiple target data tables associated with the target statement in the database.

[0100] In the present application, step 302 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0101] Step 303: Acquire association information between multiple target data tables from a table relationship knowledge base.

[0102] In the present application, step 303 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0103] Step 304: perform intent recognition on the target sentence to determine the operation intent corresponding to the target sentence.

[0104] As an implementation method, a pre-trained intent recognition model can be used to perform intent recognition on the target sentence to determine the operation intent corresponding to the target sentence.

[0105] As another way, a large model can be used to perform intent recognition on the target sentence and determine the operation intent of the target sentence. Exemplarily, a second prompt word can be generated according to the target sentence and each operation type in the database according to the corresponding prompt word template. The second prompt word is used to prompt the large model to perform the intent recognition task. The second prompt word is input into the large model to determine the target operation type corresponding to the target from each operation type, and then determine the operation intent according to the target operation type. Therefore, the accuracy of intent recognition can be improved by using a large model to determine the operation intent corresponding to the target sentence.

[0106] Among them, various types of database operations may include insertion, deletion, modification, query, etc.

[0107] For example, the second prompt word may be as follows: Currently, a user has the following operation requirement for the database: Please query the names of all users with user administrator positions in Province A. Please determine which operation the requirement is among add, delete, modify, and query. Based on the second prompt word, the example output is as follows: The requirement is a "query" operation in database operations. Specifically, this is a query (SELECT) operation, the purpose of which is to retrieve the names of all users with user administrator positions in Province A.

[0108] Step 305: Generate a first prompt word according to the target sentence, structural information, associated information and operation intention.

[0109] In the present application, the type of SQL statement to be generated can be determined according to the operation intention, and the first prompt word can be generated according to the target statement, the type of SQL statement to be generated, structural information, associated information, etc., according to the corresponding prompt word template.

[0110] For example, if the target statement is "Query the names of all users with the user administrator position in province A", the first prompt word can be as follows:

[0111] The existing user query requirements are as follows: Please generate a query SQL statement for "querying the names of all users with user administrator positions in Province A". The data tables involved are user, fwptcompany, and UserGrade. The table structures are: user(useid(user id), comcode(affiliation code), usename(user name)), fwptcompany(comcode(institution code), comname(institution name)), UserGrade(useid(user id), rade(position name)). Among them, user and fwptcompany use inner joins, and the connection field is comcode. User and UserGrade are inner joins, and the connection field is Userid. There is no foreign key constraint between the tables.

[0112] Exemplarily, the first prompt word can be generated according to the target statement, the type, structure information, association information, data volume and index information of the target data table, and the corresponding prompt word template. Thus, based on the user intention, the structure information of the target data table, the association information between the target data tables, the data volume and index information of the target data table, the large model is guided to generate SQL statements, which can improve the generation quality of SQL statements.

[0113] For example, if the target statement is "Query the names of all users with the user administrator position in province A", the first prompt word can be as follows:

[0114] The existing user query requirements are as follows: Please generate a query SQL for "querying the names of all users with user administrator positions in Province A". The data tables involved are the user table, fwptcompany table, and UserGrade table. The table structures are: user(useid(user id), comcode(affiliation code), usename(user name)), fwptcompany(comcode(institution code), comname(institution name)), UserGrade(useid(user id), grade(position name)). Among them, user and fwptcompany use inner joins, and the connection field is comcode. User and UserGrade are inner joins, and the connection field is Userid. There are no foreign key constraints between tables. To ensure the query efficiency of generated SQL, please consider the following data volume and index factors: the fwptcomany table has 100,000 data items, and an index is built on the comcode field; the user table has 80,000 data items, and an index is built on the userid field; the usergrade table has 90,000 data items, and a joint index is built on the userid and grade fields.

[0115] Step 306: input the first prompt word into the big model to obtain the SQL statement generated by the big model.

[0116] In the present application, step 306 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.

[0117] For example, the first prompt word can be as follows: The existing user query requirements are as follows: Please generate a query SQL statement for "querying the names of all users with user administrator positions in Province A". The data tables involved are the user table, fwptcompany table, and UserGrade table. The table structures are: user(useid(user id), comcode(affiliation organization code), usename(user name)), fwptcompany(comcode(organization code), comname(organization name)), UserGrade(useid(user id), rade(position name)). Among them, user and fwptcompany use inner joins, and the connection field is comcode. User and UserGrade are inner joins, and the connection field is Userid. There is no foreign key constraint between the tables.

[0118] Based on the first prompt word, the output example of the large model is as follows:

[0119] To generate a SQL query statement that meets your requirements, you can use the following SQL code:

[0120] SELECT u.usename AS User Name

[0121] FROM user u

[0122] JOIN fwptcompany c ON u.comcode=c.comcode

[0123] JOIN UserGrade ug ON u.useid=ug.useid

[0124] WHERE ug.grade='User Administrator'

[0125] and comname='Province A'

[0126] For another example, if the target statement is "Please add a new user Zhang San with the position of User Administrator in Province A", the first prompt can be as follows: The existing user addition requirements are as follows: Please generate an insert SQL statement for "Please add a new user Zhang San with the position of User Administrator in Province A". The data tables involved are the user table, the fwptcompany table, and the UserGrade table. The structures of each table are: user(useid (user ID), comcode (attribution organization code), usename (user name)), fwptcompany(comcode (organization code), comname (organization name)), UserGrade(useid (user ID), grade (position name)). Among them, user and fwptcompany use an inner join, and the join field is comcode. user and UserGrade are inner joined, and the join field is Userid. There is no foreign key constraint between the tables.

[0127] Based on this first prompt, an output example of the large model is as follows:

[0128] To add a new user Zhang San with the position of User Administrator in Province A, first, it is necessary to determine the attribution organization code (comcode) of user Zhang San. Assume this organization code is SC (representing Province A), and this organization already exists in the fwptcompany table. The following is an example of the insert SQL statement:

[0129] 1. Insert user information into the user table:

[0130] INSERT INTO user(useid,comcode,usename)

[0131] VALUES('Zhang San','SC','Zhang San');

[0132] 2. Insert position information into the UserGrade table:

[0133] INSERT INTO UserGrade(useid,grade)

[0134] VALUES('Zhang San','User Administrator');

[0135] Note: This assumes that the useid is unique in the user table and can be a string user name. If the useid needs to be a unique number or has other format requirements, you need to adjust it according to the actual situation. Make sure that the affiliated organization code SC already exists in the fwptcompany table before performing the insert operation.

[0136] For another example, if the target sentence is "Please change the organization of the user named Zhang San who has the user administrator position to City B", the first prompt word can be as follows:

[0137] The existing user modification requirements are as follows: Please generate a modification SQL statement for "Please change the organization of the user named Zhang San who has the user administrator position to City B". The data tables involved are the user table, fwptcompany table, and UserGrade table. The table structures are: user(useid(user id), comcode(affiliation organization code), usename(user name)), fwptcompany(comcode(organization code), comname(organization name)), UserGrade(useid(user id), grade(position name)). Among them, user and fwptcompany use inner joins, and the connection field is comcode. User and UserGrade are inner joins, and the connection field is Userid. There is no foreign key constraint between the tables.

[0138] Based on this first inscription, the output example of the large model is as follows:

[0139] To change the organization of a user named Zhang San who has the position of user administrator to City B, we need to first find the organization code of City B. Assume that the organization code of City B is CQ (representing City B), and this organization already exists in the fwptcompany table. The following is an example of modifying the SQL statement:

[0140] UPDATE user

[0141] SET comcode = 'CQ'

[0142] WHERE useid IN (

[0143] SELECT ug.useid

[0144] FROM UserGrade ug

[0145] INNER JOIN user u ON ug.useid = u.useid

[0146] WHERE u.usename = 'Zhang San' AND ug.grade = 'User Administrator' );

[0148] This query statement does the following things:

[0149] 1. Use a subquery to find all user IDs of users whose name is Zhang San and position is User Administrator.

[0150] 2. Use the UPDATE statement to update the comcode field of these users in the user table and set it to the institutional code CQ of City B.

[0151] Again, for the target statement "Delete all users with the position of User Administrator in Province A", the first prompt can be as follows:

[0152] The existing user deletion requirements are as follows: Please generate a delete SQL statement for "Delete all users with the position of User Administrator in Province A". The data tables involved are the user table, the fwptcompany table, and the UserGrade table. The structures of each table are: user (useid (user ID), comcode (attributed institutional code), usename (user name)), fwptcompany (comcode (institutional code), comname (institutional name)), UserGrade (useid (user ID), grade (position name)). Among them, user and fwptcompany use an inner join, and the join field is comcode. user and UserGrade are inner joined, and the join field is Userid. There are no foreign key constraints between the tables.

[0153] Based on this first prompt, the output example of the large model is as follows:

[0154] To delete all users with the position of User Administrator in Province A, we need to first determine the institutional code of Province A and find all users with the position of User Administrator. Then, we will use this information to delete the corresponding records in the UserGrade table because these records are directly related to the position of user Zhang San. Finally, if necessary, we can also delete the records in the user table.

[0155] The following is an example of a delete SQL statement:

[0156] 1. First find the institution code of Province A, assuming it is SC.

[0157] 2. Delete the user record with the user administrator position:

[0158] DELETE FROM user

[0159] WHERE useid IN (

[0160] SELECT u.useid

[0161] FROM user u

[0162] INNER JOIN fwptcompany c ON u.comcode=c.comcode

[0163] INNER JOIN UserGrade ug ON u.useid=ug.useid

[0164] WHERE c.comname = 'Province A' AND ug.grade = 'User Administrator' );

[0166] If you need to delete the records in the usergrade table at the same time, you can do the following:

[0167] DELETE FROM UserGrade

[0168] WHERE useid IN (

[0169] SELECT u.useid

[0170] FROM user u

[0171] INNER JOIN fwptcompany c ON u.comcode=c.comcode

[0172] INNER JOIN UserGrade ug ON u.useid=ug.useid

[0173] WHERE c.comname = 'Province A' AND ug.grade = 'User Administrator' )

[0175] In the embodiment of the present application, the target operation statement is recognized for its intent, the operation intent corresponding to the target statement is generated, and the first prompt word for input into the large model is generated based on the target statement, structure information, association information and operation intent. Thus, based on the structure information of the target data table, the association information between the target data tables and the user's intent, the large model is guided to generate SQL statements, which can improve the generation quality of SQL statements.

[0176] In order to implement the above embodiment, the present application also proposes a device for generating SQL statements. Figure 4 A schematic diagram of the structure of a device for generating SQL statements provided in an embodiment of the present application.

[0177] like Figure 4 As shown, the SQL statement generation device includes:

[0178] A first acquisition module 410 is used to acquire a target sentence for operating a database; wherein the target sentence is a natural language sentence;

[0179] A determination module 420, configured to determine a plurality of target data tables associated with the target statement in a database;

[0180] A second acquisition module 430 is used to acquire association information between the multiple target data tables from a table relationship knowledge base;

[0181] A generating module 440, configured to generate a first prompt word according to the target sentence, the structural information of each target data table and the associated information;

[0182] The third acquisition module 450 is used to input the first prompt word into the large model to obtain the SQL statement generated by the large model.

[0183] Furthermore, in a possible implementation of the embodiment of the present application, the generating module 440 is used to:

[0184] Parsing the target data table to determine the data volume and index information of the target data table;

[0185] The first prompt word is generated according to the target sentence, the structural information, the association information, the data volume corresponding to the target data table and the index information.

[0186] Furthermore, in a possible implementation of the embodiment of the present application, the generating module 440 is used to:

[0187] Performing intent recognition on the target sentence to determine the operation intent corresponding to the target sentence;

[0188] The first prompt word is generated according to the target sentence, the structural information, the associated information and the operation intention.

[0189] Furthermore, in a possible implementation of the embodiment of the present application, the generating module 440 is used to:

[0190] Generate a second prompt word according to the target sentence and each operation type;

[0191] Inputting the second prompt word into the large model to determine the target operation type corresponding to the target from the various operation types;

[0192] The operation intention is determined according to the target operation type.

[0193] Furthermore, in a possible implementation of the embodiment of the present application, the determining module 420 is configured to:

[0194] Obtaining metadata configuration information of each data table in the database: wherein the metadata configuration information includes the table name of the data table and description information of the data table;

[0195] According to the target statement and metadata configuration information of each data table, the target data table associated with the target statement in each data table is determined using the large model.

[0196] Furthermore, in a possible implementation of the embodiment of the present application, the association information includes at least one of the following: an association type, foreign key constraint information, a connection field, and a connection method of the connection field.

[0197] It should be noted that the above explanation of the SQL statement generation method embodiment is also applicable to the SQL statement generation device of this embodiment, which will not be repeated here.

[0198] In an embodiment of the present application, by determining multiple target data tables associated with the target statement in the database, generating SQL statements based on the target data tables can reduce the amount of calculation of the large model. According to the target statement, prompt words are generated in combination with the association information between the multiple target data tables and the table structure information of the data tables, so that the table structure information, table association information, etc. can be provided for the large model. As a result, the large model generates high-quality SQL statements based on the table structure information, table association information, etc., thereby improving the generation quality of SQL statements associated with multiple tables.

[0199] In order to implement the above embodiments, the present application also proposes an electronic device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method provided by the above embodiments.

[0200] In order to implement the above embodiments, the present application also proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the methods provided by the above embodiments.

[0201] In order to implement the above embodiments, the present application also proposes a computer program product, including a computer program, which implements the methods provided by the above embodiments when executed by a processor.

[0202] The collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in this application are in compliance with relevant laws and regulations and do not violate public order and good morals.

[0203] It should be noted that personal information from users should be collected for legitimate and reasonable purposes and not shared or sold outside of these legitimate uses. In addition, such collection / sharing should be carried out after receiving the user's informed consent, including but not limited to notifying the user to read the user agreement / user notice and sign the agreement / authorization including authorization of relevant user information before the user uses the function. In addition, any necessary steps should be taken to protect and safeguard access to such personal information data.

[0204] The present application anticipates providing implementation schemes for users to selectively block the use or access of personal information data. That is, the present disclosure anticipates providing hardware and / or software to prevent or block access to such personal information data. Once the personal information data is no longer needed, risks can be minimized by limiting data collection and deleting the data. In addition, when applicable, personal identifiers are removed from such personal information.

[0205] In the description of the aforementioned embodiments, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

[0206] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0207] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.

[0208] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.

[0209] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0210] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.

[0211] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0212] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A method for generating a SQL statement, characterized in that: The following steps are involved: Acquire a target sentence for operating a database; wherein the target sentence is a natural language sentence; Determining a plurality of target data tables associated with the target statement in a database; Acquire association information between the multiple target data tables from a table relationship knowledge base; Generate a first prompt word according to the target sentence, the structural information of each target data table and the associated information; The first prompt word is input into the big model to obtain the SQL statement generated by the big model.

2. The method according to claim 1, characterized in that The step of generating a first prompt word according to the target sentence, the structural information of each target data table and the associated information includes: Parsing the target data table to determine the data volume and index information of the target data table; The first prompt word is generated according to the target sentence, the structural information, the association information, the data volume corresponding to the target data table and the index information.

3. The method according to claim 1, characterized in that The step of generating a first prompt word according to the target sentence, the structural information of each target data table and the associated information includes: Performing intent recognition on the target sentence to determine the operation intent corresponding to the target sentence; The first prompt word is generated according to the target sentence, the structural information, the associated information and the operation intention.

4. The method according to claim 3, characterized in that The performing intention recognition on the target sentence to determine the operation intention corresponding to the target sentence includes: Generate a second prompt word according to the target sentence and each operation type; Inputting the second prompt word into the large model to determine the target operation type corresponding to the target from the various operation types; The operation intention is determined according to the target operation type.

5. The method according to claim 1, characterized in that The determining of a plurality of target data tables associated with the target sentence in the database includes: Obtaining metadata configuration information of each data table in the database: wherein the metadata configuration information includes the table name of the data table and description information of the data table; According to the target statement and metadata configuration information of each data table, the target data table associated with the target statement in each data table is determined using the large model.

6. The method according to any one of claims 1 to 5, characterized in that The association information includes at least one of the following: association type, foreign key constraint information, connection field, and connection mode of the connection field.

7. A device for generating SQL statements, characterized in that: include: A first acquisition module is used to acquire a target sentence for operating a database; wherein the target sentence is a natural language sentence; A determination module, used for determining a plurality of target data tables associated with the target statement in a database; A second acquisition module, used for acquiring association information between the plurality of target data tables from a table relationship knowledge base; A generating module, configured to generate a first prompt word according to the target sentence, the structural information of each target data table and the associated information; The third acquisition module is used to input the first prompt word into the large model to obtain the SQL statement generated by the large model.

8. The device according to claim 7, characterized in that The generating module is used for: Parsing the target data table to determine the data volume and index information of the target data table; The first prompt word is generated according to the target sentence, the structural information, the association information, the data volume corresponding to the target data table and the index information.

9. The device according to claim 7, characterized in that The generating module is used for: Performing intent recognition on the target sentence to determine the operation intent corresponding to the target sentence; The first prompt word is generated according to the target sentence, the structural information, the associated information and the operation intention.

10. The device according to claim 9, characterized in that The generating module is used for: Generate a second prompt word according to the target sentence and each operation type; Inputting the second prompt word into the large model to determine the target operation type corresponding to the target from the various operation types; The operation intention is determined according to the target operation type.

11. The device according to claim 7, characterized in that The determining module is used to: Obtaining metadata configuration information of each data table in the database: wherein the metadata configuration information includes the table name of the data table and description information of the data table; According to the target statement and metadata configuration information of each data table, the target data table associated with the target statement in each data table is determined using the large model.

12. The device according to any one of claims 7 to 11, characterized in that The association information includes at least one of the following: association type, foreign key constraint information, connection field, and connection mode of the connection field.

13. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.

15. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.

Citation Information

Patent Citations

  • Database operation statement generation method and device, computer equipment and storage medium

    CN116756179A

  • Multi-dimensional database statistical analysis method based on large model

    CN117931898A

  • Text2SQL semantic parsing method for domain large language model

    CN118377796A

  • Query statement generation model processing method and device and computer equipment

    CN118568202A

  • SQL query statement generation system and method

    CN118585537A