Can ChatGPT query a database?

Using the AI chatbot to automate your database admin.

Can ChatGPT query a database?

Last Updated on

ChatGPT, the AI language model from OpenAI, brings artificial intelligence to database management systems. However, ChatGPT’s query capabilities may be limited by the link, or lack thereof, between it and an SQL server instance. Let’s learn how the OpenAI LLM (Large Language Model) can perform SQL queries with natural language inputs. Can ChatGPT query a database?

Can ChatGPT access a database?

No, ChatGPT cannot access a database – not directly, at least.

ChatGPT Plus and ChatGPT Enterprise, the paid subscription tiers for ChatGPT, allow the user to install plugins. Through plugins, the AI language model can interface with other software’s, and perform tasks on behalf of the humans that ordinarily use it.

Essential AI Tools

Editor’s pick
EXCLUSIVE DEAL 10,000 free bonus credits

Jasper AI

On-brand AI content wherever you create. 100,000+ customers creating real content with Jasper. One AI tool, all the best models.
Editor’s pick
TRY FOR FREE

Copy.ai

Experience the full power of an AI content generator that delivers premium results in seconds. 8 million users enjoy writing blogs 10x faster, effortlessly creating higher converting social media posts or writing more engaging emails. Sign up for a free trial.
Editor’s pick
Only $0.00015 per word!

Winston AI detector

Winston AI: The most trusted AI detector. Winston AI is the industry leading AI content detection tool to help check AI content generated with ChatGPT, GPT-4, Bard, Bing Chat, Claude, and many more LLMs.
Only $0.01 per 100 words

Originality AI detector

Originality.AI Is The Most Accurate AI Detection.Across a testing data set of 1200 data samples it achieved an accuracy of 96% while its closest competitor achieved only 35%. Useful Chrome extension. Detects across emails, Google Docs, and websites.
TRY FOR FREE

WordAI

10x Your Content Output With AI. Key features – No duplicate content, full control, in built AI content checker. Free trial available.
*Prices are subject to change. PC Guide is reader-supported. When you buy through links on our site, we may earn an affiliate commission. Learn more

The ChatGPT plugin selection includes those for data management and data analytics purposes. ChatGPT Excel plugins exist for this very purpose.

Can you connect ChatGPT to a database?

ChatGPT cannot connect to database by itself. However, with ChatGPT Plus or ChatGPT Enterprise, the AI chatbot can access the internet and any publicly available databases on it. Google Sheets can be used to create publically accessible databases for an AI chatbot, which includes Microsoft Bing Chat and Google Bard.

A Google sheets database.
A Google sheets database.

Can ChatGPT query a database?

Yes, ChatGPT can query a database, by using the ChatGPT API (or OpenAPI as its lesser known). The OpenAI API allows development of custom apps and functionality, powered by the GPT-3.5 Turbo or GPT-4 model.

SQL developers who know a little Python can run real-time analytics and complex queries using human-like text with prompt engineering. Prompt engineering is the art of knowing how to ask for what you want.

How to use ChatGPT to query a database

Data analysts will have a head start here, being that the first step in using ChatGPT to query a database is to know how to query any database. 

Thankfully, AI takes a lot of the technical know-how out of it. You don’t need to be a software engineer to use AI for database management – in truth, you barely need to know SQL syntax or other query languages, but your knowing your database schema does help. 

The way ChatGPT works is by taking an input prompt in natural human language, and feeding this into its NLP (Natural Language Processing) algorithm. It can then produce a text output – which again, can be in natural human language, or it can be code. SQL (Structured Query Language) is one such example. This behaviour can be used for various applications, including generating a MySQL or PostgreSQL script.

This isn’t an invitation to get lazy, however, as a broad AI client like ChatGPT can make mistakes. It’s best to use ChatGPT for guidance, while still using SQL server management studio in conjunction.