we are trying to create a constraint that decides whether a grade should be F or not. If a course isn’t finished then the student should get the grade F. Else the student should get another grade.
This is our constraint
ALTER TABLE Registrerad_på ADD CONSTRAINT chk_avslutadkurs CHECK (CASE WHEN FinishedCourse
= 'No' THEN Grade = 'F')
Grade is a varchar(50) column that accepts null values and FinishedCourse is the same, except it cant contain null values and it only contains ‘Yes’ values at this time. The table Registrerad_på contains data (int and varchar(50)).
The question: What is wrong with the Check, the error arises at the last “=” at the THEN statement. Please tell me if i need to add some more information, sorry if it is unclear.
Any hint would be appreciated.
Your constraint is
The skeleton syntax for a CASE statement (standard SQL) is usually
So you need at least the END keyword.
But you probably really need something more like this.
Think about adding another constraint on FinishedCourse.