插入语句与外键冲突

时间:2019-05-29 11:34:01

标签: c# tsql foreign-keys

我对以下C#代码有疑问

  

System.Data.SqlClient.SqlException:'INSERT语句与FOREIGN KEY约束“ FK__StudentRe__Stude__34C8D9D1”发生冲突。数据库“ FormativePracticalAssesment”的表“ dbo.StudentIformation”的“ Id”列中发生了冲突。   该语句已终止。'

SQL代码:

Create table StudentIformation
(
Id int primary key identity(1,1),
Name varchar(55),
Surname varchar(55),
Age int
)

Create  table StudentReport
(
Id int primary key identity(1,1),
[Subject] varchar(55),
[PasedORFailed] varchar(55),
StudentNBLink int foreign key references StudentIformation(ID)
)

INSERT INTO StudentIformation
VALUES ('Mark','Perkins',20),('Brandon','Last',18),('Nicol','Potgieter',23),('Cindy','Perkins',24)

SELECT * FROM StudentIformation SI
LEFT OUTER JOIN StudentReport SR ON SR.StudentNBLink =SI.ID

INSERT INTO StudentReport
VALUES ('IT','Pased',1),('IT','Pased',2),('Webdv','Failed',3), ('Webdv','Pased',4)

INSERT INTO Login3
VALUES ('Mark','Test')

0 个答案:

没有答案