Skip to content

Commit

Permalink
Improving MSSQL quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
slyons committed Sep 19, 2024
1 parent e62d69c commit faaac10
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions mssql/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
# Spice Demo with SalesLT dataset in MSSQL

This demo showcases how to use Spice with the SalesLT sample dataset in MSSQL.
# MSSQL Data connector

## Prerequisites

- MSSQL Server with SalesLT sample dataset
- Spice installed and configured
- The latest version of Spice. [Install Spice](https://docs.spiceai.org/getting-started/installation)
- MSSQL Server with SalesLT sample dataset (see below)

## Creating a sample SQL database

This quickstart is based around the sample SalesLT dataset. Depending on your server setup there are two approaches to loading the dataset into your database:

### New SQL Database

When creating the SQL Database through the Azure portal, you have the option to include the sample dataset as part of your deployment.

![Adding SalesLT dataset](images/screenshot.png "Adding SalesLT dataset to a new database")

## Steps
1. Obtain your SQL server ADO connection string. It should look something like this:
`Server=tcp:server.database.windows.net,1433;Initial Catalog=nrc_health_testing;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;`
### Existing SQL Database

2. Copy `.env.example` as `.env` and put the connection string in the new `.env` file in the `MSSQL_CONNECTION_STRING` field
The dataset is available as a series of [backup files](https://learn.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver16&tabs=ssms) that can be loaded using backup restore tools

3. Put your OpenAI key in the `SPICE_OPENAI_API_KEY` field
## Quickstart Steps
1. Obtain your SQL server ADO connection string. Currently, the only supported auth method is `SQL Authentication`. If you're using Azure SQL the connection strings can be found in the Portal:

3. Run Spice with `spice run`
![Connection String step 1](images/cs1.png "Connection string step 1")
![Connection String step 2](images/cs2.png "Connection string step 2")

4. In another shell run `spice sql` to connect to the Spice backend and query your data or `spice chat` to chat with your data using an LLM
2. Copy `.env` as `.env.local` and put the connection string in the new `.env.local` file in the `SPICE_MSSQL_CONNECTION_STRING` field

3. Replace `{your_password}` in `SPICE_MSSQL_CONNECTION_STRING` with your SQL user's password

```
4. Run Spice with `spice run`

5. In another shell run `spice sql` to connect to the Spice backend and query the dataset


```sql
sql> SELECT COUNT(*) FROM customer
+----------+
| count(*) |
+----------+
| 847 |
+----------+
```

```
❯ spice chat
Using model: openai
chat> How many customers do I have?
You have 847 customers.
```
Binary file added mssql/images/cs1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mssql/images/cs2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mssql/images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit faaac10

Please sign in to comment.