Developer & DevOps

Create queries from just the schema - powered by AI

29 nodes 229 118 Automatic trigger
Download

Workflow Description

Advanced automation for generating SQL queries directly from database schemas using artificial intelligence. Accepts text and file inputs, returns optimized queries with detailed explanations, and maintains complete conversation history for future reference.

How it works

  1. 1.Receive schema input from user text or uploaded file
  2. 2.Send schema data to OpenAI model for intelligent processing
  3. 3.Generate optimized SQL query with comprehensive explanations
  4. 4.Save query and history to file for documentation purposes
  5. 5.Store conversation context in memory buffer for continuity

Use cases

  • Generate complex queries from database schema without manual coding
  • Rapidly develop and test queries with step-by-step logic explanation
  • Archive and document project queries with full conversation context

Requirements

  • Valid OpenAI API key with appropriate permissions
  • MySQL database or SQL schema file as input source
  • File system access for reading and writing documentation

Service Value

Ideal as a smart automation service combining integrations and AI to produce ready-to-use results.

Apps Used

OpenAI Memory MySQL Read Write File Chat Trigger AI Agent

Details

Trigger Automatic trigger
Nodes 29
Apps 6
Views 229
Downloads 118

How to Use

  1. 1.Click "Download Template"
  2. 2.Open your n8n dashboard
  3. 3.Go to Workflows > Import from File
  4. 4.Select downloaded file and configure credentials

Nodes Used (29)

/

OpenAI Chat Model

OpenAI

#1

Window Buffer Memory

Memory Buffer Window

#2

No Operation, do nothing

No Op

#3

List all tables in a database

My Sql

#4

Extract database schema

My Sql

#5

Add table name to output

Set

#6

Convert data to binary

Convert To File

#7

Save file locally

Read Write File

#8

Extract data from file

Extract From File

#9

Chat Trigger

Chat Trigger

#10

AI Agent

Agent

#11

Sticky Note

Sticky Note

#12

Sticky Note1

Sticky Note

#13

When clicking "Test workflow"

Manual Trigger

#14

Sticky Note2

Sticky Note

#15

Sticky Note3

Sticky Note

#16

Combine schema data and chat input

Set

#17

Load the schema from the local file

Read Write File

#18

Extract SQL query

Set

#19

Check if query exists

If

#20

Sticky Note4

Sticky Note

#21

Sticky Note5

Sticky Note

#22

Sticky Note7

Sticky Note

#23

Sticky Note6

Sticky Note

#24

Sticky Note8

Sticky Note

#25

Format query results

Set

#26

Run SQL query

My Sql

#27

Prepare final output

Set

#28

Combine query result and chat answer

Merge

#29