将大城市文本文件导入 SQL 服务器

Import Large Cities Text File into SQL server

我正在尝试将城市名称的文本文件导入 SQL 服务器 2012。文件大小为 1.45 GB,我正在使用 SQL 服务器导入和导出向导来完成这项工作,但是每次我收到这个错误:

  • Copying to [dbo].[worldcitiespop] (Error) Messages Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "City" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)

    Error 0xc020902a: Data Flow Task 1: The "Source - worldcitiespop_txt.Outputs[Flat File Source Output].Columns[City]" failed because truncation occurred, and the truncation row disposition on "Source - worldcitiespop_txt.Outputs[Flat File Source Output].Columns[City]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component. (SQL Server Import and Export Wizard)

    Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "C:\Users\elsho\Downloads\worldcitiespop.txt\worldcitiespop.txt" on data row 114091. (SQL Server Import and Export Wizard)

    Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Source - worldcitiespop_txt returned error code 0xC0202092. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure. (SQL Server Import and Export Wizard)

我将 Table 字段大小更改为文本类型以避免数据长度问题,但这没有帮助,请指教。

谢谢

我强烈建议您使用分段 table。将 table 导入具有宽 nvarchar() 文本字段的暂存 table。

如果您无法成功执行此操作,则数据文件本身可能已损坏。

加载到暂存区后 table,将数据(经过适当的转换)插入最终形式(然后构建索引)。当数据已经在 table 中时,比在沮丧地一遍又一遍地尝试导入它时更容易发现此类问题。