mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-22 14:07:26 +00:00
* docs: jira * docs: formatting + Client Credentials grant type * docs: connection string pgsql * docs: parameterized queries mysql * docs: parameterized queries in PostgreSQL * docs: update mysql example * docs: TJDB sql editor * docs: add metadata to REST API * docs: add, update postgresql media * docs: add metadata to graphql * docs: update parameterized queries * docs: add parameterized queries for mssql * docs: add SSL Cert to mysql * docs: TJDB SQL restricted commands * docs: update JIRA token location * docs: update delete issue example * docs: update find user by query example * docs: remove session id from get assignable users * docs: use correct image for get issues for board * docs: update create issue example * docs: update delete issue media * docs: update assignable users media * docs: update examples * docs: update key desc * docs: v2.68.0-Beta
99 lines
3.5 KiB
Markdown
99 lines
3.5 KiB
Markdown
---
|
|
id: mssql
|
|
title: MS SQL Server / Azure SQL Databases
|
|
---
|
|
|
|
ToolJet can connect to MS SQL Server & Azure SQL databases to read and write data.
|
|
|
|
<div style={{paddingTop:'24px'}}>
|
|
|
|
## Connection
|
|
|
|
To establish a connection with the MS SQL Server data source, click on the **+ Add new Data source** button located on the query panel or navigate to the [Data Sources](/docs/data-sources/overview) page from the ToolJet dashboard.
|
|
|
|
:::info
|
|
Please make sure the **Host/IP** of the database is accessible from your VPC if you have self-hosted ToolJet. If you are using ToolJet cloud, please **whitelist** our IP.
|
|
:::
|
|
|
|
ToolJet requires the following to connect to your PostgreSQL database.
|
|
|
|
- **Host**
|
|
- **Port**
|
|
- **Username**
|
|
- **Password**
|
|
- **Azure** (Select this option if you are using Azure SQL databases)
|
|
|
|
**Note:** It is recommended to create a new database user so that you can control the access levels of ToolJet.
|
|
|
|
<img className="screenshot-full" src="/img/datasource-reference/mssql/connect.png" alt="ToolJet - Redis connection"/>
|
|
|
|
|
|
</div>
|
|
|
|
<div style={{paddingTop:'24px'}}>
|
|
|
|
## Querying SQL Server / Azure SQL Databases
|
|
|
|
1. Click on **+ Add** button of the query manager at the bottom panel of the editor.
|
|
2. Select the database added in the previous step as the data source.
|
|
|
|
Once the SQL data source is added, you can create queries to read and write data to the database. You can create queries from the **[Query Panel](/docs/app-builder/query-panel#query-manager)** located at the bottom panel of the app builder.
|
|
|
|
### SQL Mode
|
|
|
|
SQL mode can be used to query MS SQL Server / Azure SQL Databases using SQL queries.
|
|
|
|
1. Select **SQL mode** from the dropdown.
|
|
2. Enter the SQL query in the editor.
|
|
3. Click on the **Run** button to run the query.
|
|
|
|
#### Example
|
|
```sql
|
|
SELECT * FROM users
|
|
```
|
|
|
|
<img className="screenshot-full" src="/img/datasource-reference/mssql/sql mode.png" alt="ToolJet mssql sql mode" style={{marginBottom:'15px'}}/>
|
|
|
|
#### **Parameterized queries**:
|
|
|
|
ToolJet offers support for parameterized SQL queries, which enhance security by preventing SQL injection and allow for dynamic query construction. To implement parameterized queries:
|
|
|
|
1. Use `:parameter_name` as placeholders in your SQL query where you want to insert parameters.
|
|
2. In the **Parameters** section below the query editor, add key-value pairs for each parameter.
|
|
3. The keys should match the parameter names used in the query (without the colon).
|
|
4. The values can be static values or dynamic values using the `{{ }}` notation.
|
|
|
|
<div style={{textAlign: 'center'}}>
|
|
<img className="screenshot-full" src="/img/datasource-reference/mssql/parameterized-query.png" alt="Postgresql parameterized SQL queries"/>
|
|
</div>
|
|
|
|
**Example:**
|
|
```yaml
|
|
Query: SELECT * FROM users WHERE username = :username
|
|
SQL Parameters:
|
|
Key: username
|
|
Value: oliver // or {{ components.username.value }}
|
|
```
|
|
|
|
### GUI Mode
|
|
|
|
GUI mode can be used to query MS SQL Server / Azure SQL Databases without writing queries.
|
|
|
|
1. Select **GUI mode** from the dropdown.
|
|
2. Choose the operation **Bulk update using the primary key**.
|
|
3. Enter the **Table** name and **Primary key** column name.
|
|
4. In the editor, enter the records in the form of an array of objects.
|
|
5. Click on the **Run** button to run the query.
|
|
|
|
#### Example
|
|
```json
|
|
{{ [ {id: 1, channel: 33}, {id: 2, channel: 24} ] }}
|
|
```
|
|
|
|
<img className="screenshot-full" src="/img/datasource-reference/mssql/gui mode.png" alt="ToolJet mssql gui mode"/>
|
|
|
|
:::tip
|
|
Query results can be transformed using transformations. Read our transformations documentation to see how: [link](/docs/tutorial/transformations)
|
|
:::
|
|
|
|
</div>
|