SQL Database Agent

Connect Junet to your SQL databases (MSSQL, MySQL, PostgreSQL) to query and analyze data using natural language

Overview

The Microsoft SQL Database Agent enables you to connect SQL databases to Junet and query them using natural language. The agent automatically understands your database schema and translates your questions into SQL queries.

Supported Databases

  • Microsoft SQL Server (MSSQL)
  • MySQL
  • PostgreSQL
  • MariaDB
  • Other SQL-compatible databases

Prerequisites

Before you begin, make sure you have:

  • Database server accessible from your Junet instance
  • Database credentials (username and password)
  • Database name you want to query
  • Server hostname/IP and port number
  • Read permissions on the database (minimum requirement)

For security reasons, it's recommended to create a read-only database user specifically for Junet.


Step 1: Prepare Database Access

For security, create a dedicated user with read-only access:

Microsoft SQL Server (MSSQL)

-- Create login
CREATE LOGIN junet_reader WITH PASSWORD = 'secure_password_here';
 
-- Create user in your database
USE your_database_name;
CREATE USER junet_reader FOR LOGIN junet_reader;
 
-- Grant read-only access
ALTER ROLE db_datareader ADD MEMBER junet_reader;

MySQL

-- Create user
CREATE USER 'junet_reader'@'%' IDENTIFIED BY 'secure_password_here';
 
-- Grant read-only access
GRANT SELECT ON your_database_name.* TO 'junet_reader'@'%';
 
-- Apply changes
FLUSH PRIVILEGES;

PostgreSQL

-- Create user
CREATE USER junet_reader WITH PASSWORD 'secure_password_here';
 
-- Grant read-only access
GRANT CONNECT ON DATABASE your_database_name TO junet_reader;
GRANT USAGE ON SCHEMA public TO junet_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO junet_reader;
 
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public 
GRANT SELECT ON TABLES TO junet_reader;

Step 2: Enable the SQL Database Agent

  1. Open Junet and navigate to the chat interface
  2. Click on the Admin Panel in the top navigation
  3. Go to Agents & Connections and Select the SQL Agent
  4. Toggle the switch to Enabled

Step 3: Add a Database Connection

  1. In the SQL Database Agent settings, click Add Connection
  2. Fill in the connection details:

Connection Name

Enter a descriptive name for this connection (e.g., "Production DB", "Customer Database", "Analytics DB")

This name appears in chat results when the agent queries this database.

Description (Optional)

Add a description to help users understand what data this database contains (e.g., "Customer orders and transactions", "Product inventory database")

Db Server

Enter the database server hostname or IP address:

localhost           # For local databases
192.168.1.100      # Internal IP address
db.company.com     # Domain name

Db Database

Enter the name of the database you want to connect to:

your_database_name

Db Username

Enter the database username (preferably the read-only user you created):

junet_reader

Db Password

Enter the password for the database user:

secure_password_here

Db Port

Enter the database port number:

DatabaseDefault Port
MSSQL1433
MySQL3306
PostgreSQL5432
MariaDB3306

Step 4: Configuration Options

Set as Default

Enable this option if you want this connection to be used by default when multiple database connections exist.

Enabled

Make sure this toggle is ON to activate the connection.


Step 5: Save the Connection

  1. Click Create Connection
  2. The connection will be validated automatically
  3. If successful, you'll see a confirmation message
  4. The connection now appears in the list with status Enabled

Step 6: Embed Database Schema (CRITICAL!)

This step is mandatory! The agent cannot query your database effectively without embedding the schema first.

After creating the connection, you must embed the database schema:

What is Schema Embedding?

Schema embedding analyzes your database structure (tables, columns, relationships, data types) and converts it into a format the AI can understand. This allows the agent to:

  • Know what tables exist
  • Understand column names and types
  • Recognize relationships between tables
  • Generate accurate SQL queries

How to Embed Schema

  1. After saving the connection, look for the Workflows section on the right side
  2. Find MSSQL Schema Embedding
  3. Click the Embed Data button
  4. The embedding process will start

Enable Notifications

Enable notifications in your user settings to receive an alert when the schema embedding is complete. This process can take several minutes for large databases.

To Enable Notifications:

  1. Click on your profile icon in the top right
  2. Go to SettingsNotifications
  3. Enable Agent Workflow Notifications
  4. You'll receive a notification when embedding is complete

Embedding Progress

  • Small databases (< 10 tables): 1-2 minutes
  • Medium databases (10-100 tables): 3-10 minutes
  • Large databases (100+ tables): 10-30 minutes

You can continue using Junet while embedding is in progress. The database will be available for queries once embedding completes.


Using the SQL Database Agent

Once the schema is embedded, you can ask questions in natural language:

Simple Queries

  • "How many customers do we have?"
  • "Show me the top 10 products by sales"
  • "What's the total revenue for last month?"
  • "List all orders from yesterday"

Complex Queries

  • "Which customers have spent more than $10,000 in the last quarter?"
  • "Show me the average order value by customer segment"
  • "Find products that are low in stock and have high demand"
  • "Compare sales performance by region for this year vs last year"

Aggregations and Analytics

  • "What's the monthly revenue trend for the last 6 months?"
  • "Show me customer retention rate by cohort"
  • "Calculate the conversion rate from leads to customers"
  • "What are the most profitable product categories?"

Managing Multiple Databases

You can connect multiple databases and query them separately:

Example Setup

  • Connection 1: Production Database (orders, customers)
  • Connection 2: Analytics Database (reports, metrics)
  • Connection 3: Inventory Database (products, stock levels)

Best Practices

Security

Use Read-Only Accounts

  • Never use admin or write-access accounts
  • Create dedicated read-only users for Junet
  • Limit permissions to only necessary tables
  • Regularly audit user permissions

Protect Sensitive Data

  • Use User Groups to restrict access to sensitive databases
  • Consider creating views that exclude sensitive columns (PII)
  • Enable row-level security if your database supports it
  • Monitor query logs for unusual activity

Connection Security

  • Use SSL/TLS connections when possible
  • Keep database servers in private networks
  • Use strong passwords (16+ characters)
  • Rotate database credentials regularly (every 90 days)

Supported SQL Features

Query Types

  • ✅ SELECT statements
  • ✅ JOINs (INNER, LEFT, RIGHT, FULL)
  • ✅ Aggregations (COUNT, SUM, AVG, MIN, MAX)
  • ✅ GROUP BY and HAVING
  • ✅ ORDER BY and LIMIT/TOP
  • ✅ Subqueries
  • ✅ Common Table Expressions (CTEs)
  • ❌ INSERT, UPDATE, DELETE (read-only)
  • ❌ CREATE, DROP, ALTER (DDL blocked)

Functions

  • ✅ Date/time functions
  • ✅ String functions
  • ✅ Mathematical functions
  • ✅ Conditional logic (CASE WHEN)
  • ✅ Window functions (ROW_NUMBER, RANK, etc.)

Limitations

Technical Limitations

  • Maximum query execution time: 30 seconds
  • Maximum result set: 1,000 rows
  • Only one active query per user at a time

Security Limitations

  • No DDL (CREATE, ALTER, DROP) commands
  • No DML write operations (INSERT, UPDATE, DELETE)
  • No stored procedure execution
  • No dynamic SQL execution
  • No EXEC/EXECUTE commands

Schema Limitations

  • Maximum 1,000 tables per database
  • Maximum 500 columns per table
  • Complex views may not be fully understood
  • Materialized views treated as regular tables

Common Use Cases

Business Analytics

"What's our monthly recurring revenue growth rate?"

Customer Insights

"Show me customers who haven't purchased in the last 90 days"

Inventory Management

"Which products are below reorder threshold?"

Sales Performance

"Compare sales by salesperson for Q1 vs Q2"

Financial Reporting

"Calculate total expenses by category for last fiscal year"

Operations

"Show me average order fulfillment time by warehouse"

SQL Database Agent | Junet.io Documentation