You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can continue data set exploration by appending `WHERE`, `GROUP BY` and other clauses based on the result set of the first query.
@@ -101,8 +101,8 @@ A shared access signature (SAS) provides delegated access to files in a storage
101
101
102
102
```sql
103
103
-- Create MASTER KEY if it doesn't exist in the database:
104
-
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='<Some Very Strong Password Here>'
105
-
GO
104
+
CREATE MASTER KEY
105
+
ENCRYPTION BY PASSWORD ='<Some Very Strong Password Here>';
106
106
```
107
107
108
108
1. When a SAS token is generated, it includes a question mark (`?`) at the beginning of the token. To use the token, you must remove the question mark (`?`) when creating a credential. For example:
@@ -111,7 +111,6 @@ A shared access signature (SAS) provides delegated access to files in a storage
111
111
CREATE DATABASE SCOPED CREDENTIAL MyCredential
112
112
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
113
113
SECRET = 'sv=secret string here';
114
-
GO
115
114
```
116
115
117
116
### [Managed identity](#tab/managed-identity)
@@ -166,7 +165,7 @@ An external data source is an abstraction that enables easy referencing of a fil
When accessing nonpublic storage accounts, along with the location, you also need to reference a database scoped credential with encapsulated authentication parameters. The following script creates an external data source pointing to the file path, and referencing a database-scoped credential.
@@ -176,8 +175,8 @@ When accessing nonpublic storage accounts, along with the location, you also nee
176
175
CREATE EXTERNAL DATA SOURCE MyPrivateExternalDataSource
It's also convenient to add columns with the file location data to a view using the `filepath()` function for easier and more performant filtering. Using views can reduce the number of files and the amount of data the query on top of the view needs to read and process when filtered by any of those columns:
@@ -350,7 +349,7 @@ FROM OPENROWSET(
350
349
BULK 'yellow/puYear=*/puMonth=*/*.parquet',
351
350
DATA_SOURCE = 'NYCTaxiExternalDataSource',
352
351
FORMAT = 'parquet'
353
-
) AS filerows
352
+
) AS filerows;
354
353
```
355
354
356
355
Views also enable reporting and analytic tools like Power BI to consume results of `OPENROWSET`.
@@ -364,8 +363,7 @@ External tables encapsulate access to files making the querying experience almos
364
363
CREATE EXTERNAL FILE FORMAT DemoFileFormat
365
364
WITH (
366
365
FORMAT_TYPE=PARQUET
367
-
)
368
-
GO
366
+
);
369
367
370
368
--Create external table:
371
369
CREATE EXTERNAL TABLE tbl_TaxiRides(
@@ -396,7 +394,6 @@ WITH (
396
394
DATA_SOURCE = NYCTaxiExternalDataSource,
397
395
FILE_FORMAT = DemoFileFormat
398
396
);
399
-
GO
400
397
```
401
398
402
399
Once the external table is created, you can query it just like any other table:
@@ -445,49 +442,7 @@ ORDER BY
445
442
446
443
If your stored data isn't partitioned, consider partitioning it to improve query performance.
447
444
448
-
If you are using external tables, `filepath()` and `filename()` functions are supported but not in the WHERE clause. You can still filter by `filename` or `filepath` if you use them in computed columns. The following example demonstrates this:
A character string that represents the friendly name (or `PROGID`) of the data provider as specified in the registry. *provider_name* has no default value. Provider name examples are `Microsoft.Jet.OLEDB.4.0`, `SQLNCLI`, or `MSDASQL`.
72
-
73
-
#### '*datasource*'
74
-
75
-
A string constant that corresponds to a particular OLE DB data source. *datasource* is the `DBPROP_INIT_DATASOURCE` property to be passed to the `IDBProperties` interface of the provider to initialize the provider. Typically, this string includes the name of the database file, the name of a database server, or a name that the provider understands for locating the database or databases.
76
-
77
-
Data source can be file path `C:\SAMPLES\Northwind.mdb'` for `Microsoft.Jet.OLEDB.4.0` provider, or connection string `Server=Seattle1;Trusted_Connection=yes;` for `SQLNCLI` provider.
78
-
79
-
#### '*user_id*'
80
-
81
-
A string constant that is the user name passed to the specified data provider. *user_id* specifies the security context for the connection and is passed in as the `DBPROP_AUTH_USERID` property to initialize the provider. *user_id* can't be a Microsoft Windows login name.
82
-
83
-
#### '*password*'
84
-
85
-
A string constant that is the user password to be passed to the data provider. *password* is passed in as the `DBPROP_AUTH_PASSWORD` property when initializing the provider. *password* can't be a Microsoft Windows password.
86
-
87
-
#### '*provider_string*'
88
-
89
-
A provider-specific connection string that is passed in as the `DBPROP_INIT_PROVIDERSTRING` property to initialize the OLE DB provider. *provider_string* typically encapsulates all the connection information required to initialize the provider. For a list of keywords that the [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Native Client OLE DB provider recognizes, see [Initialization and Authorization Properties (Native Client OLE DB Provider)](../../relational-databases/native-client-ole-db-data-source-objects/initialization-and-authorization-properties.md).
90
-
91
-
<aid="table_or_view"></a>
92
-
93
-
#### [ catalog. ][ schema. ] object
94
-
95
-
Remote table or view containing the data that `OPENROWSET` should read. It can be three-part-name object with the following components:
96
-
97
-
-*catalog* (optional) - the name of the catalog or database in which the specified object resides.
98
-
-*schema* (optional) - the name of the schema or object owner for the specified object.
99
-
-*object* - the object name that uniquely identifies the object to work with.
100
-
101
-
#### '*query*'
102
-
103
-
A string constant sent to and executed by the provider. The local instance of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] doesn't process this query, but processes query results returned by the provider, a pass-through query. Pass-through queries are useful when used on providers that don't make available their tabular data through table names, but only through a command language. Pass-through queries are supported on the remote server, as long as the query provider supports the OLE DB Command object and its mandatory interfaces. For more information, see [SQL Server Native Client (OLE DB) Interfaces](../../relational-databases/native-client-ole-db-interfaces/sql-server-native-client-ole-db-interfaces.md).
104
-
105
-
```sql
106
-
SELECT a.*
107
-
FROM OPENROWSET(
108
-
'SQLNCLI',
109
-
'Server=Seattle1;Trusted_Connection=yes;',
110
-
'SELECT TOP 10 GroupName, Name FROM AdventureWorks2022.HumanResources.Department'
111
-
) AS a;
112
-
```
113
-
114
69
### BULK arguments
115
70
116
71
Uses the `BULK` rowset provider for `OPENROWSET` to read data from a file. In [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)], `OPENROWSET` can read from a data file without loading the data into a target table. This lets you use `OPENROWSET` with a basic `SELECT` statement.
@@ -162,6 +117,10 @@ The default for *maximum_errors* is 10.
162
117
163
118
### BULK data processing options
164
119
120
+
#### DATA_SOURCE
121
+
122
+
`DATA_SOURCE` is the external location created with [CREATE EXTERNAL DATA SOURCE](../statements/create-external-data-source-transact-sql?view=azuresqldb-current&preserve-view=true).
123
+
165
124
#### FIRSTROW = *first_row*
166
125
167
126
Specifies the number of the first row to load. The default is 1. This indicates the first row in the specified data file. The row numbers are determined by counting the row terminators. `FIRSTROW` is 1-based.
Copy file name to clipboardExpand all lines: docs/t-sql/functions/openrowset-transact-sql.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,13 +60,13 @@ OPENROWSET
60
60
61
61
#### '*provider_name*'
62
62
63
-
A character string that represents the friendly name (or `PROGID`) of the data provider as specified in the registry. *provider_name* has no default value. Provider name examples are `Microsoft.Jet.OLEDB.4.0`, `SQLNCLI`, or `MSDASQL`.
63
+
A character string that represents the friendly name (or `PROGID`) of the data provider as specified in the registry. *provider_name* has no default value. Provider name examples are `MSOLEDBSQL`, `Microsoft.Jet.OLEDB.4.0`, or `MSDASQL`.
64
64
65
65
#### '*datasource*'
66
66
67
67
A string constant that corresponds to a particular data source. *datasource* is the `DBPROP_INIT_DATASOURCE` property to be passed to the `IDBProperties` interface of the provider to initialize the provider. Typically, this string includes the name of the database file, the name of a database server, or a name that the provider understands for locating the database or databases.
68
68
69
-
Data source can be file path `C:\SAMPLES\Northwind.mdb'` for `Microsoft.Jet.OLEDB.4.0` provider, or connection string `Server=Seattle1;Trusted_Connection=yes;` for `SQLNCLI` provider.
69
+
Data source can be file path `C:\SAMPLES\Northwind.mdb'` for `Microsoft.Jet.OLEDB.4.0` provider, or connection string `Server=Seattle1;Trusted_Connection=yes;` for `MSOLEDBSQL` provider.
70
70
71
71
#### '*user_id*'
72
72
@@ -127,7 +127,7 @@ For more information, see [SQL Server Native Client (OLE DB) Interfaces](../../r
127
127
```sql
128
128
SELECT a.*
129
129
FROM OPENROWSET(
130
-
'SQLNCLI',
130
+
'MSOLEDBSQL',
131
131
'Server=Seattle1;Trusted_Connection=yes;',
132
132
'SELECT TOP 10 GroupName, Name FROM AdventureWorks2022.HumanResources.Department'
133
133
) AS a;
@@ -162,12 +162,12 @@ This section provides general examples to demonstrate how to use OPENROWSET.
162
162
163
163
### A. Use OPENROWSET with SELECT and the SQL Server Native Client OLE DB Provider
164
164
165
-
The following example uses the [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Native Client OLE DB provider to access the `HumanResources.Department` table in the [!INCLUDE [ssSampleDBobject](../../includes/sssampledbobject-md.md)] database on the remote server `Seattle1`. (Use SQLNCLI and [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] will redirect to the latest version of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Native Client OLE DB Provider.) A `SELECT` statement is used to define the row set returned. The provider string contains the `Server` and `Trusted_Connection` keywords. These keywords are recognized by the [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Native Client OLE DB provider.
165
+
The following example uses the [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Native Client OLE DB provider to access the `HumanResources.Department` table in the [!INCLUDE [ssSampleDBobject](../../includes/sssampledbobject-md.md)] database on the remote server `Seattle1`. (Use `MSOLEDBSQL` for the modern Microsoft SQL Server OLE DB Data Provider that replaced `SQLNCLI`.) A `SELECT` statement is used to define the row set returned. The provider string contains the `Server` and `Trusted_Connection` keywords. These keywords are recognized by the [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] Native Client OLE DB provider.
Copy file name to clipboardExpand all lines: docs/t-sql/statements/create-external-data-source-transact-sql.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -555,7 +555,7 @@ WITH (
555
555
556
556
### E. Create an external data source for bulk operations retrieving data from Azure Storage
557
557
558
-
**Applies to:**[!INCLUDE [sssql17-md](../../includes/sssql17-md.md)] and later.
558
+
**Applies to:**[!INCLUDE [sssql17-md](../../includes/sssql17-md.md)] and later versions.
559
559
560
560
Use the following data source for bulk operations using [BULK INSERT](bulk-insert-transact-sql.md) or [OPENROWSET](../functions/openrowset-bulk-transact-sql.md). The credential must set `SHARED ACCESS SIGNATURE` as the identity, mustn't have the leading `?` in the SAS token, must have at least read permission on the file that should be loaded (for example `srt=o&sp=r`), and the expiration period should be valid (all dates are in UTC time). For more information on shared access signatures, see [Using Shared Access Signatures (SAS)](/azure/storage/common/storage-sas-overview).
561
561
@@ -684,7 +684,7 @@ Additional notes and guidance when setting the location:
684
684
685
685
<!-- See also docs\t-sql\statements\create-external-data-source-connection-options.md -->
686
686
687
-
Specified for [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later. Specifies additional options when connecting over `ODBC` to an external data source. To use multiple connection options, separate them by a semi-colon.
687
+
Specified for [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later versions. Specifies additional options when connecting over `ODBC` to an external data source. To use multiple connection options, separate them by a semi-colon.
688
688
689
689
Applies to generic `ODBC` connections, as well as built-in `ODBC` connectors for [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)], Oracle, Teradata, MongoDB, and Azure Cosmos DB API for MongoDB.
**Applies to**: [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions
1146
1146
1147
1147
Creates an external data source for PolyBase queries. External data sources are used to establish connectivity and support these primary use cases:
1148
1148
@@ -1154,7 +1154,7 @@ Creates an external data source for PolyBase queries. External data sources are
1154
1154
1155
1155
## <aid="syntax"></a> Syntax for SQL Server 2022
1156
1156
1157
-
## Syntax for SQL Server 2022 and later
1157
+
## Syntax for SQL Server 2022 and later versions
1158
1158
1159
1159
```syntaxsql
1160
1160
CREATE EXTERNAL DATA SOURCE <data_source_name>
@@ -1226,7 +1226,7 @@ Additional notes and guidance when setting the location:
1226
1226
1227
1227
<!-- See also docs\t-sql\statements\create-external-data-source-connection-options.md -->
1228
1228
1229
-
Specified for [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later. Specifies additional options when connecting over `ODBC` to an external data source. To use multiple connection options, separate them by a semi-colon.
1229
+
Specified for [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later versions. Specifies additional options when connecting over `ODBC` to an external data source. To use multiple connection options, separate them by a semi-colon.
1230
1230
1231
1231
Applies to generic `ODBC` connections, as well as built-in `ODBC` connectors for [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)], Oracle, Teradata, MongoDB, and Azure Cosmos DB API for MongoDB.
1232
1232
@@ -1241,7 +1241,7 @@ Starting in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] Cumulative Upd
1241
1241
1242
1242
#### PUSHDOWN = ON | OFF
1243
1243
1244
-
**Applies to: [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later.** States whether computation can be pushed down to the external data source. It is on by default.
1244
+
**Applies to: [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later versions.** States whether computation can be pushed down to the external data source. It is on by default.
1245
1245
1246
1246
`PUSHDOWN` is supported when connecting to [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)], Oracle, Teradata, MongoDB, the Azure Cosmos DB API for MongoDB, or ODBC at the external data source level.
1247
1247
@@ -1678,7 +1678,7 @@ For a more detailed example on how to access delta files stored on Azure Data L
1678
1678
1679
1679
### H. Create an external data source for bulk operations retrieving data from Azure Storage
1680
1680
1681
-
**Applies to:**[!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later.
1681
+
**Applies to:**[!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions.
1682
1682
1683
1683
Use the following data source for bulk operations using [BULK INSERT (Transact-SQL)](bulk-insert-transact-sql.md) or [OPENROWSET (Transact-SQL)](../functions/openrowset-bulk-transact-sql.md). The credential must set `SHARED ACCESS SIGNATURE` as the identity, mustn't have the leading `?` in the SAS token, must have at least read permission on the file that should be loaded (for example `srt=o&sp=r`), and the expiration period should be valid (all dates are in UTC time). For more information on shared access signatures, see [Using Shared Access Signatures (SAS)](/azure/storage/common/storage-sas-overview).
0 commit comments