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
The `BULK INSERT` and `OPENROWSET` statements can directly access a file in Azure Blob Storage. The following examples use data from a CSV (comma separated value) file (named `inv-2017-01-19.csv`), stored in a container (named `Week3`), stored in a storage account (named `newinvoices`).
22
22
23
-
> [!IMPORTANT]
24
-
> All the paths to the container and to the files on Blob Storage are **case-sensitive**. If not correct, it might return an error like "Cannot bulk load. The file "file.csv" does not exist or you don't have file access rights."
23
+
All the paths to the container and to the files on Blob Storage are **case-sensitive**. If not correct, it might return an error like the following example:
24
+
25
+
> Cannot bulk load. The file "file.csv" does not exist or you don't have file access rights.
description: When you bulk import to a SQL Server table or bulk export from a table, a format file can store field format information for a data file relative to a table.
# Format files to import or export data (SQL Server)
17
17
18
-
[!INCLUDE[SQL Server Azure SQL Database PDW](../../includes/applies-to-version/sql-asdb-asdbmi-pdw.md)]
18
+
[!INCLUDE[SQL Server Azure SQL Database PDW](../../includes/applies-to-version/sql-asdb-asdbmi-pdw.md)]
19
19
20
-
When you bulk import data into a [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] table or bulk export data from a table, you can use a *format file* to store all the format information that is required to bulk export or bulk import data. This includes format information for each field in a data file relative to that table.
20
+
When you bulk import data into a [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] table or bulk export data from a table, you can use a *format file* to store all the format information that is required to bulk export or bulk import data. This includes format information for each field in a data file relative to that table.
21
21
22
-
[!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] supports two types of format files: XML formats and non-XML format files. Both non-XML format files and XML format files contain descriptions of every field in a data file, and XML format files also contain descriptions of the corresponding table columns. Generally, XML and non-XML format files are interchangeable. However, we recommend that you use the XML syntax for new format files because they provide several advantages over non-XML format files. For more information, see [XML Format Files (SQL Server)](../../relational-databases/import-export/xml-format-files-sql-server.md).
22
+
[!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] supports two types of format files: XML formats and non-XML format files. Both non-XML format files and XML format files contain descriptions of every field in a data file, and XML format files also contain descriptions of the corresponding table columns. Generally, XML and non-XML format files are interchangeable. However, we recommend that you use the XML syntax for new format files because they provide several advantages over non-XML format files. For more information, see [XML Format Files (SQL Server)](xml-format-files-sql-server.md).
23
23
24
24
> [!NOTE]
25
-
> This syntax, including bulk insert, is not supported in Azure Synapse Analytics. [!INCLUDE [Use ADF or PolyBase instead of Synapse Bulk Insert](includes/bulk-insert-synapse.md)]
25
+
> This syntax, including bulk insert, isn't supported in Azure Synapse Analytics. [!INCLUDE [Use ADF or PolyBase instead of Synapse Bulk Insert](includes/bulk-insert-synapse.md)]
26
26
27
-
## <aid="Benefits"></a> Benefits of format files
27
+
## Benefits of format files
28
28
29
-
- Provides a flexible system for writing data files that requires little or no editing to comply with other data formats or to read data files from other software.
30
-
- Enables you to bulk import data without having to add or delete unnecessary data or to reorder existing data in the data file. Format files are particularly useful when a mismatch exists between fields in the data file and columns in the table.
29
+
Format files provide a flexible system for writing data files that requires little or no editing to comply with other data formats or to read data files from other software.
31
30
32
-
## <aid="ExamplesOfFFs"></a> Examples of format files
31
+
You can bulk import data without having to add or delete unnecessary data or to reorder existing data in the data file. Format files can be useful when a mismatch exists between fields in the data file and columns in the table.
33
32
34
-
The following examples show the layout of a non-XML format file and of an XML format file. These format files correspond to the `HumanResources.myTeam` table in the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] sample database. This table contains four columns: `EmployeeID`, `Name`, `Title`, and `ModifiedDate`.
33
+
## Examples of format files
34
+
35
+
The following examples show the layout of a non-XML format file and of an XML format file. These format files correspond to the `HumanResources.myTeam` table in the [!INCLUDE [ssSampleDBobject](../../includes/sssampledbobject-md.md)] sample database. This table contains four columns: `EmployeeID`, `Name`, `Title`, and `ModifiedDate`.
35
36
36
37
> [!NOTE]
37
-
> For information about this table and how to create it, see [HumanResources.myTeam Sample Table (SQL Server)](../../relational-databases/import-export/humanresources-myteam-sample-table-sql-server.md).
38
+
> For information about this table and how to create it, see [HumanResources.myTeam sample table (SQL Server)](humanresources-myteam-sample-table-sql-server.md).
38
39
39
40
### A. Use a non-XML format file
40
41
41
-
The following non-XML format file uses the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] native data format for the `HumanResources.myTeam` table. This format file was created by using the following `bcp` command.
42
+
The following non-XML format file uses the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] native data format for the `HumanResources.myTeam` table. This format file was created by using the following `bcp` command.
42
43
43
44
```cmd
44
45
bcp AdventureWorks2022.HumanResources.myTeam format nul -f myTeam.Fmt -n -T
45
46
```
46
47
47
-
The `bcp` command defaults to a local, default instance of SQL Server with Windows Authentication. You can specify other instance and login information as desired, for more information see [bcp Utility](../../tools/bcp-utility.md). For example, to specify a remote server named instance with Windows Authentication, use:
48
+
The `bcp` command defaults to a local, default instance of [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] with Windows Authentication. You can specify other instance and login information as desired, for more information, see [bcp Utility](../../tools/bcp-utility.md). For example, to specify a remote server named instance with Windows Authentication, use:
48
49
49
50
```cmd
50
51
bcp AdventureWorks2022.HumanResources.myTeam format nul -f myTeam.Fmt -n -T -S servername/instancename
51
52
```
52
53
53
-
The contents of this format file are as follows, starting with the major version number of SQL Server, and the table metadata information.
54
+
The contents of this format file are as follows, starting with the major version number of [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)], and the table metadata information.
54
55
55
56
```output
56
57
14.0
57
58
4
58
-
1 SQLSMALLINT 0 2 "" 1 EmployeeID ""
59
-
2 SQLNCHAR 2 100 "" 2 Name SQL_Latin1_General_CP1_CI_AS
60
-
3 SQLNCHAR 2 100 "" 3 Title SQL_Latin1_General_CP1_CI_AS
59
+
1 SQLSMALLINT 0 2 "" 1 EmployeeID ""
60
+
2 SQLNCHAR 2 100 "" 2 Name SQL_Latin1_General_CP1_CI_AS
61
+
3 SQLNCHAR 2 100 "" 3 Title SQL_Latin1_General_CP1_CI_AS
For more information, see [Non-XML Format Files (SQL Server)](../../relational-databases/import-export/non-xml-format-files-sql-server.md).
65
+
For more information, see [Use Non-XML format files (SQL Server)](non-xml-format-files-sql-server.md).
65
66
66
-
### B. Using an XML format file
67
+
### B. Use an XML format file
67
68
68
-
The following XML format file uses the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] native data format for the `HumanResources.myTeam` table. This format file was created by using the following `bcp` command.
69
+
The following XML format file uses the [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] native data format for the `HumanResources.myTeam` table. This format file was created by using the following `bcp` command.
69
70
70
71
```cmd
71
-
bcp AdventureWorks2022.HumanResources.myTeam format nul -f myTeam.Xml -x -n -T
72
+
bcp AdventureWorks2022.HumanResources.myTeam format nul -f myTeam.xml -x -n -T
72
73
```
73
74
74
75
The format file contains:
@@ -91,39 +92,39 @@ The format file contains:
91
92
</BCPFORMAT>
92
93
```
93
94
94
-
For more information, see [XML Format Files (SQL Server)](../../relational-databases/import-export/xml-format-files-sql-server.md).
95
-
96
-
## <aid="WhenFFrequired"></a> When is a format file required?
95
+
For more information, see [XML Format Files (SQL Server)](xml-format-files-sql-server.md).
97
96
98
-
- An INSERT ... SELECT * FROM OPENROWSET(BULK...) statement always requires a format file.
99
-
- For **bcp** or BULK INSERT, in simple situations, using a format file is optional and rarely necessary. However, for complex bulk-import situations, a format file is frequently required.
97
+
## When is a format file required?
100
98
101
-
Format files are required if:
99
+
Format files are usually required in the following circumstances:
102
100
101
+
- When you use an `INSERT ... SELECT * FROM OPENROWSET(BULK...)` statement.
102
+
- For complex bulk-import situations using **bcp** or `BULK INSERT`.
103
103
- The same data file is used as a source for multiple tables that have different schemas.
104
104
- The data file has a different number of fields that the target table has columns; for example:
105
105
106
-
- The target table contains at least one column for which either a default value is defined or NULL is allowed.
107
-
- The users do not have SELECT/INSERT permissions on one or more columns in the table.
106
+
- The target table contains at least one column for which either a default value is defined or `NULL` is allowed.
107
+
- The users don't have `SELECT`/`INSERT` permissions on one or more columns in the table.
108
108
- A single data file is used with two or more tables that have different schemas.
109
109
110
110
- The column order is different for the data file and table.
111
111
- The terminating characters or prefix lengths differ among the columns of the data file.
112
112
113
113
> [!NOTE]
114
-
> In the absence of a format file, if a **bcp** command specifies a data-format switch (**-n**, **-c**, **-w**, or **-N**) or a BULK INSERT operation specifies the DATAFILETYPE option, the specified data format is used as the default method of interpreting the fields of the data file.
114
+
> In the absence of a format file, if a **bcp** command specifies a data-format switch (`-n`, `-c`, `-w`, or `-N`) or a `BULK INSERT` operation specifies the `DATAFILETYPE` option, the specified data format is used as the default method of interpreting the fields of the data file.
115
115
116
-
## See also
116
+
## Related tasks
117
117
118
-
-[Non-XML Format Files (SQL Server)](../../relational-databases/import-export/non-xml-format-files-sql-server.md)
119
-
-[XML Format Files (SQL Server)](../../relational-databases/import-export/xml-format-files-sql-server.md)
120
-
-[Data Formats for Bulk Import or Bulk Export (SQL Server)](../../relational-databases/import-export/data-formats-for-bulk-import-or-bulk-export-sql-server.md)
121
-
-[bcp Utility](../../tools/bcp-utility.md)
118
+
-[Using BCP native/format file vs text file and the BOM](https://techcommunity.microsoft.com/t5/sql-server-blog/using-sqlbcp-native-format-file-vs-text-file-and-the-bom/ba-p/3194629)
119
+
-[Use Non-XML format files (SQL Server)](non-xml-format-files-sql-server.md)
120
+
-[XML Format Files (SQL Server)](xml-format-files-sql-server.md)
121
+
-[Data formats for bulk import or bulk export (SQL Server)](data-formats-for-bulk-import-or-bulk-export-sql-server.md)
122
+
-[Create a format file with bcp (SQL Server)](create-a-format-file-sql-server.md)
122
123
123
-
## <aid="RelatedTasks"></a> Next steps
124
+
## Related content
124
125
125
-
-[Create a Format File (SQL Server)](../../relational-databases/import-export/create-a-format-file-sql-server.md)
126
-
-[Use a Format File to Bulk Import Data (SQL Server)](../../relational-databases/import-export/use-a-format-file-to-bulk-import-data-sql-server.md)
127
-
-[Use a Format File to Skip a Table Column (SQL Server)](../../relational-databases/import-export/use-a-format-file-to-skip-a-table-column-sql-server.md)
128
-
-[Use a Format File to Skip a Data Field (SQL Server)](../../relational-databases/import-export/use-a-format-file-to-skip-a-data-field-sql-server.md)
129
-
-[Use a Format File to Map Table Columns to Data-File Fields (SQL Server)](../../relational-databases/import-export/use-a-format-file-to-map-table-columns-to-data-file-fields-sql-server.md)
126
+
-[bcp Utility](../../tools/bcp-utility.md)
127
+
-[Use a format file to bulk import data (SQL Server)](use-a-format-file-to-bulk-import-data-sql-server.md)
128
+
-[Use a Format file to skip a table column (SQL Server)](use-a-format-file-to-skip-a-table-column-sql-server.md)
129
+
-[Use a format file to skip a data field (SQL Server)](use-a-format-file-to-skip-a-data-field-sql-server.md)
130
+
-[Use a format file to map table columns to data-file fields (SQL Server)](use-a-format-file-to-map-table-columns-to-data-file-fields-sql-server.md)
0 commit comments