diff --git a/content/v2.0/query-data/flux/sql.md b/content/v2.0/query-data/flux/sql.md index 6baee5ac5..8d0a4db3e 100644 --- a/content/v2.0/query-data/flux/sql.md +++ b/content/v2.0/query-data/flux/sql.md @@ -4,7 +4,8 @@ seotitle: Query SQL data sources with InfluxDB list_title: Query SQL data description: > The Flux `sql` package provides functions for working with SQL data sources. - Use `sql.from()` to query SQL databases like PostgreSQL, MySQL, Snowflake, and SQLite. + Use `sql.from()` to query SQL databases like PostgreSQL, MySQL, Snowflake, + SQLite, and MS SQL Server. v2.0/tags: [query, flux, sql] menu: v2_0: @@ -30,7 +31,8 @@ list_code_example: | The [Flux](/v2.0/reference/flux) `sql` package provides functions for working with SQL data sources. [`sql.from()`](/v2.0/reference/flux/stdlib/sql/from/) lets you query SQL data sources like [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/), -[Snowflake](https://www.snowflake.com/), and [SQLite](https://www.sqlite.org/index.html), +[Snowflake](https://www.snowflake.com/), [SQLite](https://www.sqlite.org/index.html), +and [MS SQL Server](https://www.microsoft.com/en-us/sql-server/default.aspx), and use the results with InfluxDB dashboards, tasks, and other operations. - [Query a SQL data source](#query-a-sql-data-source) @@ -57,6 +59,7 @@ To query a SQL data source: [MySQL](#) [Snowflake](#) [SQLite](#) +[SQL Server](#) {{% /code-tabs %}} {{% code-tab-content %}} @@ -110,6 +113,16 @@ sql.from( ) ``` {{% /code-tab-content %}} + +{{% code-tab-content %}} +```js +sql.from( + driverName: "sqlserver", + dataSourceName: "sqlserver://user:password@localhost:1234?database=examplebdb", + query: "GO SELECT * FROM Example.Table" +) +``` +{{% /code-tab-content %}} {{< /code-tabs-wrapper >}} _See the [`sql.from()` documentation](/v2.0/reference/flux/stdlib/sql/from/) for diff --git a/content/v2.0/reference/flux/stdlib/sql/_index.md b/content/v2.0/reference/flux/stdlib/sql/_index.md index 2fd8814e0..0b393d83d 100644 --- a/content/v2.0/reference/flux/stdlib/sql/_index.md +++ b/content/v2.0/reference/flux/stdlib/sql/_index.md @@ -3,7 +3,7 @@ title: Flux SQL package list_title: SQL package description: > The Flux SQL package provides tools for working with data in SQL databases such - as MySQL, PostgreSQL, and SQLite. + as MySQL, PostgreSQL, Snowflake, SQLite, and MS SQL Server. Import the `sql` package. aliases: - /v2.0/reference/flux/functions/sql/ @@ -18,7 +18,7 @@ related: --- SQL Flux functions provide tools for working with data in SQL databases such as -MySQL, PostgreSQL, Snowflake, and SQLite. +MySQL, PostgreSQL, Snowflake, SQLite, and MS SQL Server. Import the `sql` package: ```js diff --git a/content/v2.0/reference/flux/stdlib/sql/from.md b/content/v2.0/reference/flux/stdlib/sql/from.md index 0ecc56666..e92e04474 100644 --- a/content/v2.0/reference/flux/stdlib/sql/from.md +++ b/content/v2.0/reference/flux/stdlib/sql/from.md @@ -39,6 +39,7 @@ The following drivers are available: - postgres - snowflake - sqlite3 – _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#query-an-sqlite-database)._ +- sqlserver, mssql ### dataSourceName The data source name (DSN) or connection string used to connect to the SQL database. @@ -61,6 +62,12 @@ username[:password]@hostname:port/dbname/schemaname?account=¶m # SQLite Driver DSN file:/path/to/test.db?cache=shared&mode=ro + +# MS SQL Server Driver DSNs +sqlserver://username:password@localhost:1234?database=examplebdb +server=localhost;user id=username;database=examplebdb; +server=localhost;user id=username;database=examplebdb;azure auth=ENV +server=localhost;user id=username;database=examplebdbr;azure tenant id=77e7d537;azure client id=58879ce8;azure client secret=0123456789 ``` ### query @@ -139,3 +146,18 @@ sql.from( query: "SELECT * FROM example_table" ) ``` + +### Query a SQL Server database +```js +import "sql" +import "influxdata/influxdb/secrets" + +username = secrets.get(key: "SQLSERVER_USER") +password = secrets.get(key: "SQLSERVER_PASS") + +sql.from( + driverName: "sqlserver", + dataSourceName: "sqlserver://${username}:${password}@localhost:1234?database=examplebdb", + query: "GO SELECT * FROM Example.Table" +) +``` diff --git a/content/v2.0/reference/flux/stdlib/sql/to.md b/content/v2.0/reference/flux/stdlib/sql/to.md index 4d94200ef..f4a4a071d 100644 --- a/content/v2.0/reference/flux/stdlib/sql/to.md +++ b/content/v2.0/reference/flux/stdlib/sql/to.md @@ -38,6 +38,7 @@ The following drivers are available: - postgres - snowflake - sqlite3 – _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#write-data-to-an-sqlite-database)._ +- sqlserver, mssql ### dataSourceName The data source name (DSN) or connection string used to connect to the SQL database. @@ -60,6 +61,12 @@ username[:password]@hostname:port/dbname/schemaname?account=¶m # SQLite Driver DSN file:/path/to/test.db?cache=shared&mode=rw + +# MS SQL Server Driver DSNs +sqlserver://username:password@localhost:1234?database=examplebdb +server=localhost;user id=username;database=examplebdb; +server=localhost;user id=username;database=examplebdb;azure auth=ENV +server=localhost;user id=username;database=examplebdbr;azure tenant id=77e7d537;azure client id=58879ce8;azure client secret=0123456789 ``` ### table @@ -148,3 +155,18 @@ sql.to( table: "example_table" ) ``` + +### Write data to a SQL Server database +```js +import "sql" +import "influxdata/influxdb/secrets" + +username = secrets.get(key: "SQLSERVER_USER") +password = secrets.get(key: "SQLSERVER_PASS") + +sql.to( + driverName: "sqlserver", + dataSourceName: "sqlserver://${username}:${password}@localhost:1234?database=examplebdb", + table: "Example.Table" +) +```