SQL 服务器:语句冲突

SQL Server : Statement Conflict

我正在使用 SCRUBS 并尝试 运行 在 SSMS 上工作,但我收到此错误:

Started:  3:41:55 PM  
Error: 2015-07-31 15:41:58.03     
Code: 0xC0202009     
Source: Reports Write new Reports [135]     
Description: 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 10.0"  
Hresult: 0x80004005  
Description: "The statement has been terminated.".  
An OLE DB record is available.  
Source: "Microsoft SQL Server Native Client 10.0"  
Hresult: 0x80004005  
Description: "The INSERT statement conflicted with the FOREIGN KEY   constraint "FK__Reports__ReportT__2D27B809". The conflict occurred in database  "SummitCloud_SCRUBS", table "dbo.ReportTypes", column 'ReportType'.".  
End Error

Error: 2015-07-31 15:41:58.03     
Code: 0xC0047022     
Source: Reports SSIS.Pipeline     
Description: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Write new Reports" (135) failed with error code 0xC0202009 while processing input "OLE DB Destination Input" (146). 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.  
End Error  

DTExec: The package execution returned DTSER_FAILURE (1).

我查看了 .dtsx 文件,但没有发现设计有任何问题。列 [ReportTypes].ReportType[Reports].ReportType 也具有相同的类型。所以我不确定是什么问题。

有人知道我为什么会收到这个错误吗?

谢谢

错误具体是

The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Reports__ReportT__2D27B809". The conflict occurred in database "SummitCloud_SCRUBS", table "dbo.ReportTypes", column 'ReportType'.".

这意味着您正试图在 FK 列 ReportType 中插入一些内容,而该内容在主键 table

中不作为 PK 存在

纠正方法:

  1. 在 SQL Server Management Studio
  2. 中打开数据库 SummitCloud_SCRUBS
  3. 在设计视图中打开 table dbo.ReportTypes
  4. 查看这个table上的关系,找到一个名为FK__Reports__ReportT__2D27B809的,看看主键table是什么。
  5. 检查 table 是否存在可作为 FK 插入 table 中的有效 PK 值。
  6. 尝试检查您要在该列中输入的内容。

破解:

去掉FK关系,看看table.

中得到了什么

错误与 FOREIGN KEY 约束有关,与数据类型无关。看起来您尝试输入 table 的任何值都不是 table ReportTypes

中的有效 PK