Azure SQL icon

Azure SQL

Get, add and update data in Azure SQL

Execute Query

AI-generated

Overview

This node allows you to interact with an Azure SQL database by executing SQL queries directly. It is useful for scenarios where you need to retrieve, manipulate, or manage data stored in Azure SQL databases within your n8n workflows. For example, you can use it to run SELECT queries to fetch records, or execute any valid SQL command to update or delete data.

A practical example would be querying a product table to get all products with IDs less than 40:

SELECT id, name FROM product WHERE id < 40

This node executes the query and returns the results as JSON data for further processing in your workflow.

Properties

Name Meaning
Database Name The name of the database to use. If left blank, the default database specified in the credentials will be used.
Query The SQL query string to execute. This must be a valid SQL statement such as SELECT, INSERT, UPDATE, or DELETE.

Output

The node outputs an array of JSON objects representing the rows returned by the executed SQL query. Each object corresponds to a record with key-value pairs matching the column names and their values.

If the query does not return any records (e.g., an UPDATE or DELETE operation), the output will contain a single JSON object with a message indicating successful execution:

[{ "message": "Query executed successfully" }]

In case of errors during query execution, if the node is configured to continue on failure, the output will include an error message object:

[{ "error": "Error message here" }]

The node does not output binary data.

Dependencies

  • Requires an Azure SQL database connection.
  • Needs an API authentication token or credentials that provide server address, port, user, password, and optionally domain and TLS settings.
  • Uses the mssql Node.js package internally to connect and execute queries against the Azure SQL database.

Troubleshooting

  • Connection issues: Ensure the provided credentials are correct and the Azure SQL server is accessible from the environment where n8n runs.
  • Invalid SQL syntax: Errors may occur if the query string is malformed. Verify the SQL syntax before running.
  • Timeouts: Long-running queries might time out depending on the configured request timeout in credentials.
  • Permission errors: The authenticated user must have sufficient permissions to execute the given SQL commands.
  • Empty results: If no records match the query, the output will be an empty array or a success message without data.

Common error messages:

  • "Login failed for user": Check username and password.
  • "Timeout expired": Consider increasing the request timeout setting.
  • "Invalid object name": Verify table and column names in the query.

Links and References

Discussion