{"id":107874,"date":"2025-12-04T16:00:00","date_gmt":"2025-12-04T16:00:00","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=107874"},"modified":"2025-12-08T12:59:38","modified_gmt":"2025-12-08T12:59:38","slug":"making-ai-talk-to-your-database","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/making-ai-talk-to-your-database\/","title":{"rendered":"Making AI Talk to Your Database: AI-Powered Database Queries Made Simple"},"content":{"rendered":"\n<p>Nowadays, <a href=\"https:\/\/www.red-gate.com\/simple-talk\/business-intelligence\/data-science\/introduction-to-artificial-intelligence\/\" target=\"_blank\" rel=\"noreferrer noopener\">artificial intelligence<\/a> is everywhere. It\u2019s so prevalent that even universities are <a href=\"https:\/\/hyscaler.com\/insights\/how-universities-are-integrating-ai-into-their-curriculum\/\" target=\"_blank\" rel=\"noreferrer noopener\">implementing it into their curriculums<\/a>. That\u2019s the case because on its face, AI really is immensely powerful \u2013 we can find pretty much any information on anything we desire.<\/p>\n\n\n\n<p>Beneath the surface though, <a href=\"https:\/\/www.coursera.org\/articles\/how-does-ai-work\" target=\"_blank\" rel=\"noreferrer noopener\">AI is just a tool<\/a> that learns certain patterns and draws conclusions from information on the Web to answer questions, make decisions, or craft a code sample or two. Those that have used AI in the past will know that just as it\u2019s capable of providing valuable information, AI tools can also generate <a href=\"https:\/\/www.buzzfeed.com\/carleysuthers\/weird-and-wrong-ai-responses\" target=\"_blank\" rel=\"noreferrer noopener\">inaccurate responses<\/a>, and that\u2019s why it\u2019s important to use it wisely.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-ai-and-software-development-why-it-matters\">AI and Software Development: Why It Matters<\/h2>\n\n\n\n<p>When it comes to software appliances, AI has also found its way in. You don\u2018t have to search far to find terms akin to <a href=\"https:\/\/www.red-gate.com\/simple-talk\/blogs\/vibe-coding-or-not-coding-whats-in-the-middle\/\" target=\"_blank\" rel=\"noreferrer noopener\">&#8216;vibe coding&#8217;<\/a> \u2013 a style of programming where developers focus on the &#8216;flow&#8217; of programming and how development makes them feel rather than diving deep into a code base and figuring out problems. Vibe coding is a fun slang often used in conversations as well as in memes, and was in fact recently crowned <a href=\"https:\/\/blog.collinsdictionary.com\/language-lovers\/collins-word-of-the-year-2025-ai-meets-authenticity-as-society-shifts\/\" target=\"_blank\" rel=\"noreferrer noopener\">Collins&#8217; Word of the Year for 2025.<\/a><\/p>\n\n\n\n<p>Beyond that, though, is the raw truth of software development: AI now <a href=\"https:\/\/www.ibm.com\/think\/topics\/ai-in-software-development\" target=\"_blank\" rel=\"noreferrer noopener\">assists everything<\/a>. Structural decisions, project and product management, solutions to coding issues by providing a code block to an AI chatbot \u2013 everything\u2018s on the table. Making AI part of your software ecosystem helps everything <a href=\"https:\/\/www.red-gate.com\/blog\/building-the-foundations-for-ai-readiness?utm_source=chatgpt.com#:~:text=Building%20on%20the%20AI%20opportunity\" target=\"_blank\" rel=\"noreferrer noopener\">run more efficiently<\/a>: developers move faster, projects stay in shape, managers make important decisions quicker, and <a href=\"https:\/\/www.red-gate.com\/products\/redgate-monitor\/#:~:text=problematic%20queries%20faster-,Monitor%20AI,-detects%20bottlenecks%2C%20analyzes\" target=\"_blank\" rel=\"noreferrer noopener\">databases stay healthier<\/a>.<\/p>\n\n\n\n<p>Additionally, tools with AI capabilities like <a href=\"https:\/\/www.red-gate.com\/products\/sql-prompt\/\" target=\"_blank\" rel=\"noreferrer noopener\">SLQ Prompt<\/a> help users to <a href=\"https:\/\/www.red-gate.com\/products\/sql-prompt\/#ai-powered-code\" target=\"_blank\" rel=\"noreferrer noopener\">write SQL queries<\/a>, while there are also programs that assist with database design tasks by:<br>&#8211; <a href=\"https:\/\/www.eraser.io\/ai\/erd-generator\" target=\"_blank\" rel=\"noreferrer noopener\">Creating ER diagrams<\/a><br>&#8211; Normalizing data or suggesting relationships between tables<br>&#8211; Analyzing slow queries, missing indexes or high I\/O (input\/output) usage<br>&#8211; Assist in alleviating locking issues<br>&#8211; Help with automated monitoring and anomaly detection by alerting us of unexpected query or traffic patterns, disk or memory issues, or other potential bottlenecks.<\/p>\n\n\n\n<p>Another popular client, DBeaver,<a href=\"https:\/\/dbeaver.com\/docs\/dbeaver\/AI-Smart-Assistance\/\" target=\"_blank\" rel=\"noreferrer noopener\"> has a feature called AI Assistant<\/a> where the tool provides AI-enabled assistance in creating and editing queries, answering questions, or exploring database objects.<\/p>\n\n\n\n<p>So, AI is vital for database operations too. Just always remember: give the AI tool as much detail as possible. Ask vague questions and you&#8217;ll receive vague responses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-ai-chatbots-amp-tools-work\">How AI Chatbots &amp; Tools Work<\/h2>\n\n\n\n<p>On a high level, many developers imagine that AI talking to their database would look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"603\" height=\"115\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/11\/image-15.png\" alt=\"An image showing the flow of AI talking to a database.\" class=\"wp-image-107875\" style=\"width:695px;height:auto\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/11\/image-15.png 603w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/11\/image-15-300x57.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><figcaption class=\"wp-element-caption\"><em>Figure 1: Making AI Talk to a Database<\/em><\/figcaption><\/figure>\n\n\n\n<p>That has some truth to it since we often come to AI with a brief, yet specific, problem we need a solution to. For AI chatbots like <a href=\"https:\/\/chatgpt.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">ChatGPT<\/a>, questions like \u201cwhy is the query <code>SELECT * FROM table WHERE column = \u2018value\u2019<\/code> slow?\u201d are very common because slow queries are a frequent issue. <\/p>\n\n\n\n<p>These AI tools then analyze patterns from sources and data to provide explanations or suggestions based on those patterns, making them well-suited to troubleshoot database issues.<\/p>\n\n\n\n<p>In reality, to receive helpful and actionable responses from AI, you have to consider many things applicable to your database, application, server, and use case as a whole. Some of them will include the following:<\/p>\n\n\n\n<p><strong>Your database management system<\/strong><\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>How is the database management system configured?<\/li>\n\n\n\n<li>Any replicas in use?<\/li>\n\n\n\n<li>What&#8217;s the database schema and structure?<\/li>\n\n\n\n<li><span style=\"font-size: revert;\">What data types, character sets are in use?<\/span><\/li>\n\n\n\n<li><span style=\"font-size: revert;\">Any indexes and constraints?<\/span><\/li>\n\n\n\n<li><span style=\"font-size: revert;\">What about partitions?<\/span><\/li>\n\n\n\n<li><span style=\"font-size: revert;\">Any stored procedures or views that AI needs to consider or respect?<\/span><\/li>\n\n\n\n<li>If you\u2019re working with bigger data sets, the size of your tables and files.<\/li>\n<\/ul>\n<\/div>\n\n\n<p><strong>The architecture of your application<\/strong><\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>What is the use case of your application? Does it come with heavy read\/write operations for the database<\/li>\n\n\n\n<li><span style=\"font-size: 1rem;\">What are the rules governing business operations? (e.g. can something go into the negative?)<\/span><\/li>\n\n\n\n<li>What are the typical ways your applications reads\/writes\/modifies data?<\/li>\n\n\n\n<li>How does your application\/server handle failed queries, timeouts, unexpected input, etc.?<\/li>\n<\/ul>\n<\/div>\n\n\n<p><strong>Your server<\/strong><\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>Do you use shared hosting, VPS, or a dedicated server?<\/li>\n\n\n\n<li>What are the parameters applicable to your server? What about the disk, RAM, I\/O?<\/li>\n\n\n\n<li>How many queries\/users can the server handle at once?<\/li>\n\n\n\n<li>Do you log queries executed by your application\/database? Are they backed up? (I\u2018ve heard of cases where forums backed up log files to a different server in the event of a compromise)<\/li>\n\n\n\n<li>Do you have backup servers in case of hardware failure?<\/li>\n<\/ul>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-benefits-of-ai-powered-database-queries\">Benefits of AI-Powered Database Queries<\/h2>\n\n\n\n<p>Take two different queries:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Query 1<\/strong><\/td><td><strong>Query 2<\/strong><\/td><\/tr><tr><td>Why is this JOIN query taking so long?<br>[JOIN query here]<\/td><td>Why is this JOIN query taking so long? [JOIN query here] I execute this JOIN through a custom plugin in WordPress (find its code in the attached file wp.php.) I run MySQL 8.0.44 with the following configuration: (my.cnf settings applicable to your storage engine here.)<br>My database schema and structure is attached to this prompt through the file db.sql. I run Ubuntu Linux, I have 2TB of disk space and 32GB of operating memory, with 28GB available for immediate use.<br>The use case of my application is a rental system based on WordPress 6.9.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>It\u2018s obvious that the second prompt will provide us with a better response because the AI chatbot has more information it can act on. Now, everything looks different:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"603\" height=\"212\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/11\/image-37.png\" alt=\"A graph showing the response that the second prompt provides us with.\" class=\"wp-image-107925\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/11\/image-37.png 603w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/11\/image-37-300x105.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><figcaption class=\"wp-element-caption\"><em>Figure 2: AI Considering Our Infrastructure Before Responding<\/em><\/figcaption><\/figure>\n\n\n\n<p>From the second prompt alone, AI will take different things into account:<\/p>\n\n\n<div class=\"block-core-list\">\n<ol class=\"wp-block-list\">\n<li>The version of your DBMS and the configuration surrounding it.<\/li>\n\n\n\n<li>The database schema and structure.<\/li>\n\n\n\n<li>The specific type of operating system in use (<a href=\"https:\/\/ubuntu.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ubuntu<\/a>)<\/li>\n\n\n\n<li>The amount of available disk space and the amount of operating memory.<\/li>\n\n\n\n<li>The application\/content management systems in use.<\/li>\n\n\n\n<li>The context: the fact that we\u2019re executing a JOIN query through a custom plugin in <a href=\"https:\/\/wordpress.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress<\/a>.<\/li>\n<\/ol>\n<\/div>\n\n\n<p>These won&#8217;t guarantee an 100% accurate response (even ChatGPT notes that it can make mistakes and that important information must be double-checked), but anyone can see that the response to the second question will almost surely hit the mark in terms of what we need without us returning to the chatbot to ask four additional questions afterwards, because AI will not only act on a single specific piece of context (#6) as often happens.<\/p>\n\n\n\n<p>Instead, it will know that:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li>The chatbot should only provide advice applicable specifically to <a href=\"https:\/\/dev.mysql.com\/downloads\/mysql\/8.0.html\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL 8.0.44<\/a>, not <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server<\/a>, <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/postgresql\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL<\/a>, or <a href=\"https:\/\/mariadb.com\/docs\/release-notes\/community-server\/old-releases\/mariadb-10-5-series\" target=\"_blank\" rel=\"noreferrer noopener\">MariaDB 10.5<\/a>.<\/li>\n\n\n\n<li>The chatbot should only consider Ubuntu as the OS.<\/li>\n\n\n\n<li>Constraints are in place (2TB of disk space, 32GB of operating memory.) Those will not be exceeded.<\/li>\n\n\n\n<li>AI knows what CMS is in use (WordPress 6.9) and can act on this information if necessary (provide advice on what to upgrade, implement, etc.)<\/li>\n<\/ul>\n<\/div>\n\n\n<p>Much better, isn\u2019t it?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-get-the-most-out-of-ai\">How to Get the Most Out of AI<\/h2>\n\n\n\n<p>Think of AI chatbots like <a href=\"https:\/\/hbr.org\/2025\/09\/ai-is-changing-the-structure-of-consulting-firms\" target=\"_blank\" rel=\"noreferrer noopener\">consultants<\/a> that you pay hourly for. You want them to get work done as quickly as possible to reduce cost, so you have to present them with an actionable task with as much information as possible. Not having enough information paves the way for <a href=\"https:\/\/www.apm.org.uk\/blog\/what-is-scope-creep-and-how-can-we-mitigate-it\/\" target=\"_blank\" rel=\"noreferrer noopener\">scope creep<\/a> in real world projects, and it&#8217;s not much different with AI; you want to avoid having to ask it multiple questions to receive the response you&#8217;re looking for. The more information you provide, the quicker it&#8217;ll get this to you.<\/p>\n\n\n\n<p><a href=\"https:\/\/workplace.stackexchange.com\/questions\/63349\/how-to-deal-with-customers-who-periodically-change-requirements\" target=\"_blank\" rel=\"noreferrer noopener\">Many developers have had situations where managers or customers would keep tweaking things after work is already underway<\/a> adding or modifying requirements after a portion of work has been done. <a href=\"https:\/\/www.reddit.com\/r\/ContractorUK\/comments\/1o758cf\/how_do_you_handle_clients_who_constantly_change\/\" target=\"_blank\" rel=\"noreferrer noopener\">Such \u201cscope creep\u201d is not only applicable to software<\/a> \u2013 you can get rid of it by documenting everything that you\u2019re doing (have a complete project specification \u2013 from A to Z \u2013 in the contract) or say \u201cgood idea\u201d and put the requirements down for version two.<\/p>\n\n\n\n<p>Receiving \u201csatisfying\u201d responses from an AI chatbot isn\u2019t much different: the more things AI has at hand to consider, the quicker it&#8217;ll give you something you&#8217;re happy with. Always consider the DBMS in use (different database management systems work in different ways since they\u2019re built differently), your server, application (and your CMS if you use one), and your use case.<\/p>\n\n\n\n<p>Then, be as detailed as possible in your queries to the chatbot, and don\u2019t forget that you have a head on your shoulders too. Ultimately, decisions like &#8216;how often do we back-up our databases?&#8217; should come down to you &#8211; not ChatGPT exclusively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-using-ai-best-practices\">Using AI: Best Practices<\/h2>\n\n\n\n<p>When using AI to assist you, ask clear, specific, and context-aware questions for the best (and quickest) responses. Additionally:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li><strong>Don\u2018t forget the objective<\/strong>: state the objective of what you want to achieve at the start of your question.<\/li>\n\n\n\n<li><strong>Provide context<\/strong>: what version of a specific DBMS do you use? What are the tables, partitions, indexes, and constraints within your database and how do they interact?<\/li>\n\n\n\n<li><strong>Include all applicable constraints, limits, and considerations<\/strong>: mention rules that should be respected such as the amount of available memory, security restrictions, etc.<\/li>\n\n\n\n<li><strong>Specify the output format or action<\/strong>: do you want the AI chatbot to return a piece of code to solve your issues? Actionable advice? Generate an image? Specifying the output format, e.g <em>&#8220;Return a piece of code<\/em> <em>in an SQL format that doesn\u2018t include any JOIN queries<\/em>\u201c.<\/li>\n\n\n\n<li><strong>Ask AI about multiple options or trade-offs<\/strong>: AI can come up with multiple ways to solve the same issue. You can always ask AI to compare them or suggest what\u2018s best for your specific circumstance.<\/li>\n<\/ul>\n<\/div>\n\n\n<p>You <em>can<\/em> ask AI multiple times, but receiving adequate responses 3\/3 times will inevitably lead to better results in the future than receiving them once in a while because you couldn\u2018t explain everything necessary all at once. The same applies to software: explain everything surrounding your application, then detail your issue, and you should be good to go.<\/p>\n\n\n\n<section id=\"faq\" class=\"faq-block my-5xl\">\n    <h2>FAQs<\/h2>\n\n                        <h3 class=\"mt-4xl\">1. Should I Use AI to Solve Database Issues?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Yes, absolutely. AI chatbots like ChatGPT are a very powerful tool that can help solve many software and database issues. Ensure you provide as much information as possible to help AI best assist your use case.<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">2. How Best to Use Artificial Intelligence to Solve Database Issues?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Regardless of what AI tool you use, ensure to ask it concrete, specific and context-aware questions &#8211; and don\u2018t forget to state the objective: what do you want to achieve?<\/p>\n            <\/div>\n                    <h3 class=\"mt-4xl\">3. Can I Trust Artificial Intelligence in Solving Database Problems?<\/h3>\n            <div class=\"faq-answer\">\n                <p>Yes, you can trust AI with your database issues, but make sure to verify and check every response it gives you. It&#8217;s not uncommon for AI to provide <a href=\"https:\/\/www.evidentlyai.com\/blog\/ai-failures-examples\" target=\"_blank\" rel=\"noreferrer noopener\">wrong, and sometimes even meaningless, information<\/a>.<\/p>\n            <\/div>\n            <\/section>\n\n\n\n<section id=\"my-first-block-block_1efc2dd8a03d287f34a44fd6edb6d916\" class=\"my-first-block alignwide\">\n    <div class=\"bg-brand-600 text-base-white py-5xl px-4xl rounded-sm bg-gradient-to-r from-brand-600 to-brand-500 red\">\n        <div class=\"gap-4xl items-start md:items-center flex flex-col md:flex-row justify-between\">\n            <div class=\"flex-1 col-span-10 lg:col-span-7\">\n                <h3 class=\"mt-0 font-display mb-2 text-display-sm\">Subscribe to the Simple Talk newsletter<\/h3>\n                <div class=\"child:last-of-type:mb-0\">\n                                            Get selected articles, event information, podcasts and other industry content delivered straight to your inbox every two weeks.                                    <\/div>\n            <\/div>\n                            <a href=\"https:\/\/www.red-gate.com\/simple-talk\/subscribe\/\" class=\"btn btn--secondary btn--lg\">Subscribe now<\/a>\n                    <\/div>\n    <\/div>\n<\/section>","protected":false},"excerpt":{"rendered":"<p>Learn how AI-driven tools bridge the gap between human language and databases, making data access faster, easier, and more intuitive.&hellip;<\/p>\n","protected":false},"author":339547,"featured_media":103313,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[159169,143523,53],"tags":[159075,4168,4170,5854,158978,4151],"coauthors":[146040],"class_list":["post-107874","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-databases","category-featured","tag-ai","tag-database","tag-database-administration","tag-mysql","tag-postgresql","tag-sql-server"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/107874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/339547"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=107874"}],"version-history":[{"count":5,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/107874\/revisions"}],"predecessor-version":[{"id":107956,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/107874\/revisions\/107956"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media\/103313"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=107874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=107874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=107874"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=107874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}