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

我想导入国家列表的Excel文件到我的SQL Server数据库,但我得到这个错误。 什么可能是错的?

validation(错误)
消息
错误0xc020201b:数据stream任务1:Destination – Countries.Inputs [Destination Input]的input列数不能为零。 (SQL Server导入和导出向导)

错误0xc004706b:数据stream任务1:“目标 – 国家/地区”未通过validation并返回validation状态“VS_ISBROKEN”。
(SQL Server导入和导出向导)

错误0xc004700c:数据stream任务1:一个或多个组件未通过validation。
(SQL Server导入和导出向导)

错误0xc0024107:数据stream任务1:任务validation期间出现错误。
(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行受影响)

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

我build议以下工作stream程。

  1. 导入到全新的表格,如tempExcelImport
  2. 插入OLD_TABLE从tempExcelImport中select*
  3. 这会给你更多的信息错误,给你行数。
  4. 清理您的数据(修复您的行中的错误)并转到步骤2

编辑:

当您使用导入/导出向导列映射时 ,select您的目标表作为新的表名,如tempExcelImport

目的地

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

创build目标表/文件

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

SqlServer导入向导