【问题标题】:Upload to excel files through SQL Server Management Studio通过 SQL Server Management Studio 上传到 Excel 文件
【发布时间】:2014-11-15 21:19:19
【问题描述】:

我正在尝试将带有国家/地区列表的 excel 文件导入我的 SQL Server 数据库,但出现此错误。可能有什么问题?

验证(错误)
留言
错误 0xc020201b:数据流任务 1:Destination - countries.Inputs[Destination Input] 的输入列数不能为零。 (SQL Server 导入导出向导)

错误 0xc004706b:数据流任务 1:“目的地 - 国家/地区”验证失败并返回验证状态“VS_ISBROKEN”。
(SQL Server 导入导出向导)

错误 0xc004700c:数据流任务 1:一个或多个组件验证失败。
(SQL Server 导入导出向导)

错误 0xc0024107:数据流任务 1:任务验证期间出现错误。
(SQL Server 导入导出向导)

这是我在 Excel 中的列表预览:

  • 1 阿富汗 2 阿尔巴尼亚 3 阿尔及利亚 4 美属萨摩亚 5 安道尔
    6 安哥拉 7 安圭拉 8 安提瓜和巴布达 9 阿根廷 10 亚美尼亚
    11 阿鲁巴岛 12 澳大利亚

所以当我第一次导入临时表,然后尝试复制到我的表中时,我得到了这个错误:

    - Copying to [dbo].[Countries] (Error)
Messages
Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "Unspecified error".
 (SQL Server Import and Export Wizard)

Error 0xc020901c: Data Flow Task 1: There was an error with Destination - Countries.Inputs[Destination Input].Columns[countryId] on Destination - Countries.Inputs[Destination Input]. The column status returned was: "The value violated the integrity constraints for the column.".
 (SQL Server Import and Export Wizard)

Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "Destination - Countries.Inputs[Destination Input]" failed because error code 0xC020907D occurred, and the error row disposition on "Destination - Countries.Inputs[Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)

Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Destination - Countries" (46) failed with error code 0xC0209029 while processing input "Destination Input" (59). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)

当我执行查询时,我得到:

Msg 2627, Level 14, State 1, Line 6
Violation of PRIMARY KEY constraint 'PK_dbo.Countries'. Cannot insert duplicate key in object 'dbo.Countries'. The duplicate key value is (1).
The statement has been terminated.

(26 行受影响)

【问题讨论】:

    标签: sql-server excel


    【解决方案1】:

    您必须在您的 excel 文件中进行数据清理。我认为您正在尝试导入 EXISTING 表。

    我建议遵循工作流程。

    1. 导入到全新的表,例如 tempExcelImport
    2. 插入 OLD_TABLE 从 tempExcelImport 中选择 *
    3. 这将为您的数据提供更多信息错误,为您提供行号。
    4. 清理数据(修复行中的错误)并转到第 2 步

    编辑:

    当您使用导入/导出向导Column Mappings 时,选择您的目标表作为新表名,例如 tempExcelImport

    目的地

    标识选定的目标表、视图或查询。

    创建目标表/文件

    如果目标表不存在,则指定是否创建它。

    【讨论】:

    • 是的,我正在导入到现有表中。
    • 由于现有约束,您无法将其导入该表。试试我的工作流程
    • 您在目标表中使用 IDENTITY,您需要设置身份插入。看看这个链接stackoverflow.com/questions/20948819/…
    • 您仍在使用向导。您没有使用 INSERT INTO Part。您的某些行不适合插入该表。您需要修复这些错误。
    • 好的,我按照你说的做了,现在我编辑了这个错误。
    猜你喜欢
    • 2013-07-02
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多