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

SQL触发器存储过程编译错误,sql,stored-procedures,compiler-errors,Sql,Stored Procedures,Compiler Errors,我有一个问题,是什么让我犯了这个错误: 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.StudentDe

我有一个问题,是什么让我犯了这个错误:

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表的外键引用。

Ohh并且StudentDemographic表有以下列:StudentId(int)、姓名(nvarchar(30))、性别(nvarchar(30))、出生日期(date)、StudentStatus(nvarchar(30))、StudentRace(nvarchar(30))主键是StudentID。StudentID不在StudentDemographic表中吗?您应该用您正在使用的数据库(可能是SQL Server)标记您的问题。