我有一个问题是什么给了我这个错误:
Msg 547, Level 16, State 0, Procedure AddIntoClass, Line 12
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_CourseEnrolled_StudentDemographic". The conflict occurred in database "PK_Final", table "dbo.StudentDemographic", column 'StudentID'.
到目前为止,这是我的代码:
Create Procedure AddIntoClass(@StudentID int, @CourseName nvarchar(30),
@SectionNumber nvarchar(30), @TimeOfDay nvarchar(30), @Term int)
As
Begin
Insert into CourseEnrolled
Values(@StudentID, @CourseName, @SectionNumber, @TimeOfDay, @Term)
End
EXEC AddIntoClass 2, 'Biology', '1003', '2:00pm', 2
任何帮助都会得到满足,谢谢!
答案 0 :(得分:0)
在插入CourseEnrolled表之前,学生ID值“2”应该在StudentDemographic表中可用。
您正在将CourseId值“2”插入CourseEnrolled表,该表在“StudentId”上有一个外键引用到StudentDemographic表。