|
Dev4Snow Go back to Contents – Go back to previous page Generate SQL using ChatGPT Generate SQL using ChatGPT is a feature that works with the OpenAI’s GPT-3.5 artificial-intelligence large language models that powers ChatGPT, which for this use case is utilized to convert natural language queries into SQL statements and scripts. Since this is a new technology and Dev4Snow is an early adopter this feature is still considered to be in “beta” version and subject to changes. To start Generate SQL using ChatGPT click on the option with the same name from the tree, or from the
Icons & actions:
Create a new Query Window: The Generate SQL using ChatGPT screen can have multiple Query Windows. Use this button to manually create a new window. Delete a Query Window (or all): Remove the current Query Window or all the windows. Switch between available Query Windows: The label between the arrows indicates which the current window is. If you click on the label you will see part of the content of the query on that window and you can click on it to switch to that window, or use the arrows on the sides to switch sequentially between windows. Help: Click this icon to open this help file.
Input > Supporting objects (tables/views) The Supporting objects are those objects (tables/views) that will be used by ChatGPT either to generate a query on them, as an example to build new objects, or to replace one of those objects by adding new columns or formulas. There are a some scenarios where you may not need to add supporting objects. For example you could ask ChatGPT to “Create a table for Sales Orders” without any supporting object, and it will generate a new table with the most common columns for a Sales Orders table. If you include supporting objects for that request ChatGPT will usually try to match the style of your objects to build the new table. For most scenarios you will have to add supporting objects. Follow these steps to add or remove those objects:
When clicking one of the objects in the list of Supporting Objects, the DDL of the object will be shown in the right window next to the list. Use this DDL window as a help when writing the request to ChatGPT.
Input > Your request In this area you need to specify two things:
After filling up your request you can click Generate statement to submit it to ChatGPT. If ChatGPT succeeds in generating a SQL statement the tab will be automatically switched to the Output tab and the SQL statement will show up. If you accept the results click Adopt statement and the code will be automatically moved into a new SQL window where you can execute it. If the result is not what you expect click the Input tab, modify the request and click Generate statement again. NOTE: Some SQL statements may not be fully functional, this is particularly true when generating Stored Procedures. The generated skeleton for Stored Procedures will usually come incomplete –probably this will improve in newer versions as ChatGPT evolves.
Example In this example we want to produce a query based on this Data Model:
So we need to add the three tables as Supporting Objects. For adding the tables just enter part of the name of a table in the empty box under “Add supporting object(s)” and hit <Enter> after locating it: Since we want to produce a SELECT statement, we have to pick up that statement type from the list:
And finally we just write the request in our natural language, then we click Generate statement:
The request and supporting objects are sent to ChatGPT which returns the following result in seconds:
Now you can click Adopt statement to move the query to a SQL Code window where you can run it to get the results:
IMPORTANT INFORMATION
|
|