如何使用SQL Server 2012中的导入向导在具有标识列的表中插入值

时间:2015-12-04 06:49:11

标签: sql-server-2012

我正在尝试使用sql server 2012中的导入向导在带有标识列的表中插入值。 表格如下:

CREATE TABLE dbo.Address
        (AddressID int IDENTITY NOT NULL PRIMARY KEY ,
        AddressLine varchar(100) NOT NULL,
        City varchar(50) NOT NULL,
        [State] char(2) NOT NULL,
        Zipcode int NOT NULL);

然后我在excel中创建了虚拟数据并将其保存为txt文件。我按照向导中的步骤,选择文件源作为平面文件源,选择正确的表,同时选中启用标识插入框。最后,它将数据复制到表dbo.Address时出现以下错误。

Error message - 
- Copying to [dbo].[Address] (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: "The statement has been terminated.".
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "Cannot insert the value NULL into column 'AddressID', table 'INFX543_Team8.dbo.Address'; column does not allow nulls. INSERT fails.".
 (SQL Server Import and Export Wizard)

   Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "Destination - Address.Inputs[Destination Input]" failed because error code 0xC020907B occurred, and the error row disposition on "Destination - Address.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 - Address" (26) failed with error code 0xC0209029 while processing input "Destination Input" (39). 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)

1 个答案:

答案 0 :(得分:0)

取消选中insert identity复选框,并将ZiPcode列转换为Int列。