Generate DDL from query results
Answered
After running a query, I want to to get the SQL to create a table with same column names/type as the query results. Is there a feature that generates "CREATE TABLE " script from results of a query?
I know a lot of databases can do Create table as Select... and that is labor saving in my case, but not what I'm looking for here.
If relevant, I am using Datagrip in Pychyarm
Please sign in to leave a comment.
Have you tried to invoke View query... action in query results?
There isn't a built-in feature in most database management systems (DBMS) that directly generates a "CREATE TABLE" script from the results of a query. However, you can manually extract the column names and types from the query results and use them to create the table schema. Here's a general approach you can follow to achieve this, execute your query and retrieve the result set. Access the metadata of the result set to obtain information about column names and types. Generate the "CREATE TABLE" script using the extracted column names and types. Execute the "CREATE TABLE" script to create the new table. MyAARPMedicare UHC
Is there a way to bring the textual representation of the metadata into an editor window? Maybe the macro facility of the IDE could massage it into a table definition. It seems like in principal the IDE could automate those two steps, maybe also generating a comment that it should be reviewed before use.