DEV Community

Cover image for AI Productivity Tips 1 - SQL Companion Bot with Gemini 1.5 Pro
Çalgan Aygün
Çalgan Aygün

Posted on

AI Productivity Tips 1 - SQL Companion Bot with Gemini 1.5 Pro

In my current role, I often need to analyze database records and evaluate user performance metrics to identify anomalies. However, manually writing these one-off queries across multiple tables isn't efficient, especially when dealing with complex joins. To streamline this process, I turned to AI.

Here’s a step-by-step guide on how to boost your productivity using AI for SQL queries:

  1. Start by navigating to Google AI Studio and create a new chat prompt.

Google AI Studio Snapshot

  1. Next, set up a SQL Helper system prompt. Provide your database schema in the system prompt, also specify the RDBMS you’re using so that the AI can generate queries with the correct syntax. I tested this with The DB Book's schema.

Here’s an example system prompt:

Act as a DB Admin/SQL Developer and generate the requested SQL queries based on the following DDL/Schema. Provide explanations and ensure that the queries are safe to run in a production environment. Add "Do not forget to review the SQL query before running." to all SQL responses.

RDBMS/SQL Syntax: <Your RDBMS>

My database DDL: <Your database and table DDLs>
Enter fullscreen mode Exit fullscreen mode
  1. Now, ask your query! For example, I asked: I need to identify the students who are enrolled in a course taught by Teacher 1 and list all their other courses in a comma-separated format in a column.

And just like that, the AI (thanks to Gemini 1.5 Pro) generated the query I needed.

Chat Snapshot

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay