INF: SQL Server 7.0 BCP and Code Page ConversionID: Q199819
|
The bulk copy program (BCP) utility included with SQL Server 7.0 works differently from the BCP utility included with previous versions of SQL Server. These changes can have an effect on code page conversion during bulk copy operations. This article describes those changes and provides examples of code page conversion to clarify the issues involved.
Previous versions of the BCP utility were based on the DB-Library API. Character code translation between ANSI and OEM code pages was determined by the AutoAnsiToOem client configuration setting. This setting was disabled by default in SQL Server 4.21a and enabled by default in SQL Server 6.0 and 6.5. However, the character code translation was only enabled when data was copied from OEM clients to ANSI SQL Servers or from ANSI clients to OEM SQL Servers. No character code conversion would occur if AutoAnsiToOem was disabled or if data was being transferred between an OEM server and an OEM client.
If your SQL Server has a code page of 125n (where "n" is a single digit; for example, 1252) you have an ANSI SQL Server. If your SQL Server has any other code page, it is an OEM code page SQL Server. Code page 850 (Multilingual) was the default character code page for SQL Server 4.21 and code page 1252 (also known as Latin 1 or ANSI) was the default code page for SQL Server 6.0 and 6.5. You can determine which code page is used by your SQL Server by running the sp_helpsort stored procedure from Query Analyzer.
The client code page is the OEM code page for the operating system on which BCP is run. Microsoft Windows NT, Microsoft Windows 95, and Windows 98 operating systems have both an ANSI code page and an OEM code page; these are determined by the country settings. The computer's ANSI code page is stored in the following registry value:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ACP
For U.S. English versions of Windows NT, Windows 95, and Windows 98, the default OEM code page is 437 (U.S. English). The computer's OEM code page is stored in the following registry value:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP
To verify the client OEM code page on Windows NT, Windows 95 and Windows 98 computers, run chcp from the command line. To verify that data in a file is stored in the proper code page, you must use the appropriate editor. ANSI data should look correct in any GUI editor (such as Notepad, WordPad, or Microsoft Word). OEM data should look correct in a command-line tool (such as type or edit). To verify that data in SQL Server is stored in the proper code page, you can use the ASCII(char_expr) string function.
AutoAnsiToOem code page conversion only applies to DB-Library applications. Previous versions of the BCP utility, being DB-Library applications, were affected by this setting. However, the SQL Server 7.0 BCP utility is not a DB-Library application and is not affected by the AutoAnsiToOem setting. Unless you specify otherwise, BCP in SQL Server 7.0 will always convert data exported from and imported to SQL Server 7.0 using the client computer's OEM code page. (The SQL Server 7.0 Books Online is incorrect when it states that the ANSI/Windows code page is used for conversion during import.)
The version of BCP included with SQL Server 7.0 can be instructed to convert data according to a code page different from the client's OEM code page with the use of the new /C (or -C) command-line switch. The code page specified with the /C parameter determines the code page of the input (or output) file when data is bulk copied into or out of char, varchar, or text columns. The following are examples of how the /C parameter can be used:
/CACP | Convert to/from using the client ANSI code page |
/COEMCP | Convert to/from using the client OEM code page |
/C850 | Convert to/from using code page 850 (can be any code page) |
/CRAW | No conversion |
Q177561 HOWTO: Add and Enable Additional Languages in Windows NT
BCP pubs.dbo.authors in C:\authors.txt
BCP pubs.dbo.authors out C:\authors.txt
BCP pubs.dbo.authors out C:\authors.txt -Usa -CRAW
BCP pubs.dbo.authors in C:\authors.txt -Usa -C1252
Q153449 INF: SQL Server Code Pages and AutoAnsiToOem Behavior
Q165051 INF: Installing a DBCS Code Page for SQL Server
Q177561 HOWTO: Add and Enable Additional Languages in Windows NT
Additional query words: cp international language codepage codepages win 9x win9x win95 win98 winnt
Keywords : SSrvBCP
Version : winnt:7.0
Platform : winnt
Issue type : kbinfo
Last Reviewed: May 3, 1999