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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:17:07+00:00 2026-06-03T01:17:07+00:00

I have a question regarding enforce a constraint to my table. I have a

  • 0

I have a question regarding enforce a constraint to my table.
I have a table called workson and a table called staff, each staff has specific title(supervisor,authorizer,manager,…). I need to ensure that the supervisor and the authorizer cannot be the same staff on workson table.The cardinality between them is many to many. I am not sure how to do it.
Can you please advise me to solve this problem?

Thanks

  • 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-03T01:17:09+00:00Added an answer on June 3, 2026 at 1:17 am

    Consider the following query

    SELECT AssignmentNo, StaffNo
      FROM worksOnStaff
     WHERE StaffType = 'supervisor'
    INTERSECT 
    SELECT AssignmentNo, StaffNo
      FROM worksOnStaff
     WHERE StaffType = 'authorizer'
    

    When the data in the table satisifes your constraint the above query will be the empty set i.e.

    CHECK ( NOT EXISTS ( SELECT AssignmentNo, StaffNo
                           FROM worksOnStaff
                          WHERE StaffType = 'supervisor'
                         INTERSECT 
                         SELECT AssignmentNo, StaffNo
                           FROM worksOnStaff
                          WHERE StaffType = 'authorizer' ) );
    

    The problem is, few SQL products allow a subquery in a CHECK constraint.

    The usual workaround is to implment the same logic in procedural code e.g. using a trigger or forcing users to update data via a stored procedures (by removing update privileges on the base tables) that ensure the constraint is never violated. You have to take care to serialize updates properly without making the whole thing run like glue.

    Happily, there is an excellent book on the subject:

    Applied Mathematics for Database Professionals By Lex de Haan, Toon Koppelaars

    For implementing constraints that cannot be declared to the DBMS, we prefer to follow the triggered procedural strategy… Like declared constraints, the triggered procedural strategy cannot be subverted; …is likely to create a more manageable code architecture …[however] implementing efficient data integrity code for these constraints through triggers is far from being a trivial task…
    However, you’ll experience that by implementing table constraints regularly and becoming
    proficient in doing so, implementing table constraints procedurally is in general quite
    doable…

    execution model EM6: On-Transition-Effect-Property Plus Optimized-Query

    1. Translate the formal specification into a constraint validation query.
    2. Develop code to maintain transition effects.
    3. Devise transition effect (TE) queries that ensure the constraint validation query is only run when
      necessary.
    4. Discover a means to optimize the constraint validation query by having the TE query
      provide values that can be used in the validation query.
    5. Devise and add a serialization strategy to the data integrity (DI) code.

    They give full details on how to implement such a strategy in Oracle which can be ported to other SQL products.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a question regarding something which has been bugging me for some time now.I'm
I have a question regarding Git. The place where I work has 2 developers:
I have a question regarding CSS3 Gradients and a plugin for jQuery called color
I have a question regarding a platform I'm developing called e-cidadania (GPL). One of
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding some CSS that I'm sure has a simple solution,
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have question regarding disabling browser caching. I have already found few solutions, and
I have a question regarding dependency injection. say i want to create a class

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.