Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:40:11+00:00 2026-06-13T00:40:11+00:00

we are trying to create a constraint that decides whether a grade should be

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:40:13+00:00Added an answer on June 13, 2026 at 12:40 am

    Your constraint is

    ALTER TABLE Registrerad_på 
    ADD CONSTRAINT chk_avslutadkurs 
    CHECK (CASE WHEN FinishedCourse = 'No' THEN Grade = 'F')
    

    The skeleton syntax for a CASE statement (standard SQL) is usually

    CASE WHEN ... THEN ... ELSE ... END 
    

    So you need at least the END keyword.

    CHECK (CASE WHEN FinishedCourse = 'No' THEN Grade = 'F' END)
    

    But you probably really need something more like this.

    CHECK (CASE WHEN FinishedCourse = 'No' THEN Grade = 'F' 
                WHEN FinishedCourse = 'Yes' THEN Grade IN ('A','B','C','D','F')
                ELSE Grade = 'Somebody let some bad data into FinishedCourse'
           END)
    

    Think about adding another constraint on FinishedCourse.

    CHECK (FinishedCourse IN ('Yes', 'No') )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a constraint on an oracle database that says the following:
I'm trying to create the following check constraint. ( [Href] IS NOT NULL AND
I am trying to create a unique constraint on two fields in a table.
I am trying to create a check constraint on an access (jet?) table. So,
Trying to create a new Dedicated Cache Role in Windows Azure but get the
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I'm trying to create a table that has a primary key (Department_ID) that auto
I am trying to create a successful route for an entity that only has
I was trying to create a table that has a one to many relationships.
I am trying to create a tree from a source that provides: the 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.