docs/docs/databases/ms-sql-server/getting-started/docker.mdx
import Thumbnail from '@site/src/components/Thumbnail';
:::info Note
Support for MS SQL Server on M1/M2 Macs was added in version v2.15.0.
:::
Get the Hasura MS SQL Server docker compose file:
# in a new directory run
wget https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/docker-compose-ms-sql-server/docker-compose.yaml
# or run
curl https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/docker-compose-ms-sql-server/docker-compose.yaml -o docker-compose.yaml
:::info Note
This docker compose file utilizes the tempdb mssql database which is primarily used for testing. While this is a quick
way to get up and running using MS SQL with the Hasura GraphQL Engine, other solutions should be utilized for production
databases.
:::
The following command will run:
$ docker compose up -d
Check if the containers are running:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1bbfb6c6311d hasura/graphql-engine:v2.8.4 "graphql-engine serve" 4 seconds ago Up 2 seconds 0.0.0.0:8080->8080/tcp hasura-graphql-engine-1
1ce5806438bb mcr.microsoft.com/mssql/server:2022-latest "/opt/mssql/bin/perm…" 4 seconds ago Up 3 seconds 1433/tcp hasura-mssql-1
0e09d1f31c0e postgres:14 "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 5432/tcp hasura-postgres-1
Head to http://localhost:8080/console to open the Hasura Console.
Head to the Data > Manage databases section on the Console to add your MS SQL Server as a source to Hasura. You'll
need your ODBC connection string. Make sure that your ODBC driver is set to version 17.
Here are 2 examples of what your connection strings might look like:
Testing with SQL Server running locally on Mac:
Driver={ODBC Driver 18 for SQL Server};Server=tcp:host.docker.internal,1433;Database=tempdb;Uid=sa;Pwd=Password123;Encrypt=optional
A SQL Server instance on Azure SQL Serverless:
Driver={ODBC Driver 18 for SQL Server};Server=tcp:db.<hostname>.com,1433;Database=<db-name>;Uid=<username>;Pwd=<password>;Encrypt=yes;TrustServerCertificate=no;ConnectionTimeout=30;
If you're testing Hasura with SQL Server running locally, read this guide on Docker networking in case you're not sure how to make sure that your SQL Server database is reachable from the Hasura docker container on Linux, Mac or Windows.
<Thumbnail src="/img/databases/ms-sql-server/manage-databases_console_2.10.1.png" alt="Manage databases" width="1000px" />
<Thumbnail src="/img/databases/ms-sql-server/connect-ms-sql-db_console_2.10.1.png" alt="Add source" width="1000px" />Once you add the database, you'll see your database pop up on the sidebar.
If you have existing tables, head to the database page by clicking on the database name on the sidebar. You should see a list of tables.
<Thumbnail src="/img/databases/ms-sql-server/manage-db_step-3_console_2.10.1.png" alt="Manage my-db" width="1000px" />Track tables selectively or all of them so that Hasura can introspect the tables and create the corresponding GraphQL schema.
<Thumbnail src="/img/databases/ms-sql-server/track-tables_step-3_console_2.10.1.png" alt="Track tables" width="1000px" />
If you have foreign keys, you'll also see suggested relationships. Again, you can choose to track them selectively or all at once.
<Thumbnail src="/img/databases/ms-sql-server/track-foreign-key-rel_step-3_console_2.10.1.png" alt="Track relationships" width="1000px" />
If you don't have existing tables, head to the Run SQL window to run SQL against your SQL Server database and create tables or hit the Create Table button to create a table.
If you're running raw SQL queries to create your tables, Don't forget to check "track metadata" at the bottom of the Run SQL window to make sure Hasura tracks your new database objects in its GraphQL schema.
<Thumbnail src="/img/databases/ms-sql-server/run-sql_step-3_console_2.10.1.png" alt="Run SQL to create table" width="1000px" />
Head to the API tab in the Console and try running a GraphQL query! Use the explorer sidebar on GraphQL to get help in
creating a GraphQL query.
Hasura supports queries, subscriptions, relationships and permissions on MS SQL Server.
Please watch this space to get the latest docs on how you can try these features out via the Console or by manipulating Metadata in JSON/YAML directly.
If you'd like to stay informed about the status of SQL Server support, subscribe to our newsletter and join our discord!
:::info Additional Resources
This Hands-on Demo walks you through Getting Started with Hasura on SQL Server & common use cases. - View Recording here.
:::