Back to list

SQL Assistant: How to Build SQL Assistant in Slack or Microsoft Teams without Coding

Create an AI SQL Assistant that generates SQL queries for your database.

Yes, right. AI can write SQL queries for you. It can understand your database schema, generate SQL queries, and even interact with you to enhance them.

Let's create a bot that helps you write SQL queries, and invite the bot to your communication platforms, such as Slack or Microsoft Teams. It takes 20 minutes to create this without coding.

The image below shows how it works in Slack. Awesome, isn't it?

SQL Assistant Example

How to Create It

Don't worry. You don't need engineering knowledge to create yours.

Here are the simple steps:

  1. Extract database schema.
  2. Create an Assistant using OpenAI or Anthropic.
  3. Invite the Assistant to your communication platform using Runbear.

Let's go through one by one.

1. Extracting database schema

This is the only step you may need help from engineers.

You can extract database schema in many ways. For example, you can extract PostgreSQL database schema using this command:

psql -c "\d *"

With proper parameters, you will get table descriptions like this:

                                  Table "public.User"
   Column   |              Type              | Collation | Nullable |      Default
------------+--------------------------------+-----------+----------+-------------------
 id         | uuid                           |           | not null |
 email      | text                           |           | not null |
 createdAt  | timestamp(6) with time zone    |           | not null | CURRENT_TIMESTAMP
 updatedAt  | timestamp(6) with time zone    |           | not null |
 firstName  | text                           |           |          |
 lastName   | text                           |           |          |
 orgId      | text                           |           | not null |

2. Creating an Assistant

If you are a Runbear user, simply visit the "Assistants" page and click the "Create" button to create your Assistant that uses OpenAI or Anthropic.

All you need is to write simple instructions and attach the table descriptions. Here is an example:

You are the SQL Bot tasked with generating SQL queries based on user
requests. Utilize the provided table schema to retrieve the
information. Only use the specified tables and columns. Do not assume
the existence of any tables or columns not listed. If you are unable
to construct SQL for a given user query, acknowledge the limitation
rather than producing arbitrary SQL.

Table descriptions:

                                  Table "public.User"
   Column   |              Type              | Collation | Nullable |      Default
------------+--------------------------------+-----------+----------+-------------------
 id         | uuid                           |           | not null |
 email      | text                           |           | not null |
 createdAt  | timestamp(6) with time zone    |           | not null | CURRENT_TIMESTAMP
...

3. Inviting the Assistant to your communication platform

Using Runbear, this can be done with several clicks.

Click a button to integrate your communication platform, such as Slack or Microsoft Teams, connect the Assistant and the channel, and you're all set.

Try It Now

Join Runbear now and empower your team to achieve more with less! If you need help, don't hesitate to book a demo.