gpt4 book ai didi

sql - 尽管每列都使用了 varchar(MAX),但导入 CSV 文件时 SQL Server 中仍出现错误

转载 作者:行者123 更新时间:2023-12-01 17:37:02 27 4
gpt4 key购买 nike

我正在尝试将一个大型 CSV 文件(多个文件)插入到 SQL Server 中,但是一旦我完成导入向导并最终尝试导入该文件我收到以下错误报告:

  • 执行(错误)消息

Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column ""Title"" 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 导入和导出向导)

Error 0xc020902a: Data Flow Task 1: The "Source - Train_csv.Outputs[Flat File Source Output].Columns["Title"]" failed because truncation occurred, and the truncation row disposition on "Source - Train_csv.Outputs[Flat File Source Output].Columns["Title"]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.

(SQL Server 导入和导出向导)

Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "C:\Train.csv" on data row 2.

(SQL Server 导入和导出向导)

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Source - Train_csv 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 导入和导出向导)

我创建了表来首先插入文件,并将每一列设置为保存 varchar(MAX),所以我不明白如何仍然存在此截断问题。我做错了什么?

最佳答案

在 SQL Server 导入和导出向导中,您可以在高级选项卡中调整源数据类型(如果创建新表,这些数据类型将成为输出的数据类型,否则仅用于处理源数据)。

数据类型与 MS SQL 中的数据类型有很大不同,不是 VARCHAR(255),而是 DT_STR,并且输出列宽可以设置为 255 。对于VARCHAR(MAX),它是DT_TEXT

因此,在“数据源”选择的“高级”选项卡中,将任何违规列的数据类型从“DT_STR”更改为“DT_TEXT”(您可以选择多个列并一次性更改它们)。

Import and Export Wizard - Data Source - Advanced

关于sql - 尽管每列都使用了 varchar(MAX),但导入 CSV 文件时 SQL Server 中仍出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18600040/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com