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 8303389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:31:18+00:00 2026-06-08T17:31:18+00:00

I have the following table. CLASS_HAS_STUDENTS ( PER_SSN INTEGER NOT NULL, PER_YEAR INTEGER NOT

  • 0

I have the following table.

CLASS_HAS_STUDENTS (
    PER_SSN INTEGER NOT NULL,
    PER_YEAR INTEGER NOT NULL, /*These two are PKs for a student*/
    SCHOOL_CODE INTEGER NOT NULL, /*PK for a school*/
    CLASS_YEAR INTEGER NOT NULL,
    CLASS_NUMBER INTEGER NOT NULL,
    CLASS_TEACHTYPE CHAR(3) NOT NULL, /*These three are PKs for a class*/
    STUDCLASS_STATUS CHAR(1) NOT NULL
        constraint CKC_STUDCLASS_STATUS_CLASS_TI check (StudClass_Status IN ('E', 'Y', 'T', 'P', 'F')),
    STUDCLASS_LISTNUMBER INTEGER NOT NULL,
    STUDCLASS_ROLLNUMBER INTEGER NOT NULL
);

(This code lacks some minor constraints)

Now, I need a way to check that one PER_SSN/PER_YEAR (a person’s PK) can only have one ‘E’ (“Enrolled”) status. I can’t do this with a trigger (given I’m selecting from the same table) and I don’t know if I can do this with a check constraint (can I use COUNT() here?). Any help is 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-08T17:31:21+00:00Added an answer on June 8, 2026 at 5:31 pm

    You can create a function-based unique index to enforce this sort of thing. You can’t create a constraint as such.

    This takes advantage of the fact that Oracle b-tree indexes do not index NULL data so the index will only have entries for the rows where studclass_status is E.

    CREATE UNIQUE INDEX idx_one_enrolled
        ON class_has_students( CASE WHEN studclass_status = 'E'
                                    THEN per_ssn
                                    ELSE null
                                END,
                               CASE WHEN studclass_status = 'E'
                                    THEN per_year
                                    ELSE null
                                END );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two models: School and User, and a HABTM relationship between
I have the following two table (which are tied in with Spring security -
I have a database with the following table structures... The Customer table has two
I have the following database table object: public class Goal { @DatabaseField(generatedId = true)
I have the following code in my context, and no explicit table-class mapping, yet
I have the following entity class : @Entity @Table(name = THE_TREE, catalog = ,
I have the following mapping: @Entity @Table(name = Prequalifications) public class Prequalification implements Serializable
I have the following mapping for my table in MySql: <class name=Tag, namespace table=tags
I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
I have a webpage including the following div: <div class='book_box'> <table border=0 cellspacing=0> <tr>

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.