通过SQL Server Management Studio上传到Excel文件

时间:2014-11-15 21:19:20

标签: sql-server excel

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

  

验证(错误)
  消息
  错误0xc020201b:数据流任务1:目标 - Countries.Inputs [目标输入]的输入列数不能为零。    (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 Aruba 12 Australia

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

    - 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行受影响)

1 个答案:

答案 0 :(得分:1)

您必须在excel文件中进行数据清理。我想您正在尝试导入到一个EXISTING表。

我建议遵循工作流程。

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

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

      

    目的地

         

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

         

    创建目标表/文件

         

    指定是否创建目标表(如果目标表尚不存在)。

    SqlServer Import Wizard