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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:22:57+00:00 2026-05-20T16:22:57+00:00

I have a situation like the following join table: A_ID B_ID 1 27 1

  • 0

I have a situation like the following join table:

A_ID  B_ID
1     27
1     314
1     5

I need to put a constraint on the table that will prevent a duplicate group from being entered. In other words:

A_ID  B_ID
2     27
2     314
2     5

should fail, but

A_ID  B_ID
3     27
3     314

should succeed, because it’s a distinct group.

The 2 ways I’ve thought of are:

  1. Pivot the table in a materialize view based upon the order and put a unique key on the pivot fields. I don’t like this because in Oracle I have to limit the number of rows in a group because of both the pivoting rules, and the 32-column index limitation (thought of a way around this second problem, but still).
  2. Create some unique hash value on the combination of the B_IDs and make that unique. Maybe I’m not enough of a mathematician, but I can’t think of a way to do this that doesn’t limit the number of values that I can use for B_ID.

I feel like there’s something obvious I’m missing here, like I could just add some sort of an ordering column and set a different unique key, but I’ve done quite a bit of reading and haven’t come up with anything. It might also be that the data model I inherited is flawed, but I can’t think of anything that would give me similar flexibility.

  • 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-05-20T16:22:57+00:00Added an answer on May 20, 2026 at 4:22 pm

    Firstly a regular constraint can’t work.

    If the set with A_ID of 1 exists, and then session 1 inserts a record with A_ID 2 and B_ID of 27, session 2 inserts (2,314) and session 3 inserts (2,5), then none of those would see a conflict to cause a constraint violation. Triggers won’t work either. Equally, if a set existed of (6,99), then it would be difficult for another session to create a new set of (6,99,300).

    The MV with ‘refresh on commit’ could work, preventing the last session from successfully committing. I’d look more at the hashing option, summing up the hashed B_ID’s for each A_ID

    select table_name, sum(ora_hash(column_id)), count(*)
    from user_tab_columns
    group by table_name
    

    While hash collisions are possible, they are very unlikely.

    If you are on 11g check out LISTAGG too.

    select table_name, listagg(column_id||':') within group (order by column_id) 
    from user_tab_columns
    group by table_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation that looks like the following code: #include <iostream> class A
I have the following situation: excel-like application, that is accessible from internet. 2 users
The situation is like this: I have an Observable Collection that has a bunch
So I have the following situation. I have a configuration class config.py that holds
I would like to have a stored procedure that will update values in a
I have a situation where I'd like to execute javadoc in a project that
My situation is like following. I have a App.xaml which includes Style for ListView
I'm using mysql/php/apache . I have the following situation: 2 tables where I need
I have the following situation: table User (id, name) table Belonging (id, name, color)
How can I best handle a situation like the following? I have a constructor

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.