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

Sql server 2012 如何在SQL server 2012中使用导入向导在具有标识列的表中插入值,sql-server-2012,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, Zi

我正在尝试使用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)



取消选中“插入标识”复选框,并将ZiPcode列转换为Int列。

谢谢Praveen。它成功了。我还有一个疑问。假设我还有一个表-创建表dbo.VehicleBuyer(VehicleBuyerID int IDENTITY NOT NULL主键,AddressID int NOT NULL外键引用dbo.Address(AddressID),FirstName varchar(50)NOT NULL,LastName varchar(50)NOT NULL,PhoneNumber int NOT NULL,EmailID varchar(100)NOT NULL);因此,在本例中,在创建虚拟数据时,是否向addressID添加值?外键约束如何与导入向导一起工作?您好,Kanz,是的,您需要向vehiclebuyer表中的addressid添加值。当您加载不带检查约束的数据alter table时,请执行加载并再次添加约束。
   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)