繁体   English   中英

SQL触发器存储过程编译错误

[英]SQL Trigger Store Procedure Compile Error

我对什么给我这个错误有疑问:

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

任何帮助将被申请,谢谢!

在插入CourseEnrolled表之前,StudentDemographic表中的学生ID值应为“ 2”。

您正在将“ StudentId”值“ 2”插入CourseEnrolled表中,该表在“ StudentId”上具有对StudentDemographic表的外键引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM