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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:29:54+00:00 2026-05-19T00:29:54+00:00

I really had a hard time knowing what words to put into the title

  • 0

I really had a hard time knowing what words to put into the title of my question, as I am not especially sure if there is a database pattern related to my problem. I will try to simplify matters as much as possible to get directly to the heart of the issue.

Suppose I have some tables.
The first one is a list of widget types:

create table widget_types (
    widget_type_id number(7,0) primary key,
    description varchar2(50)
);

The next one contains icons:

create table icons (
    icon_id number(7,0) primary key,
    picture blob
);

Even though the users get to select their preferred widget, there is a predefined subset of widgets that they can choose from for each widget type.

create table icon_associations (
    widget_type_id number(7,0) references widget_types,
    icon_id number(7,0) references icons,
    primary key (widget_type_id, icon_id)
);

create table icon_prefs (
    user_id number(7,0) references users,
    widget_type_id number(7,0),
    icon_id number(7,0),
    primary key (user_id, widget_type_id),
    foreign key (widget_type_id, icon_id) references icon_associations
);

Pretty simple so far.

Let us now assume that if we are displaying an icon to a user who has not set up his preferences, we choose one of the appropriate images associated with the current widget. I’d like to specify the preferred icon to display in such a case, and here’s where I run into my problem:

alter table icon_associations 
    add ( is_preferred char(1) check( is_preferred in ('y','n') ) )
;

I do not see how I can enforce that for each widget_type there is one, and only one, row having is_preferred set to ‘y’.

I know that in MySQL, I am able to write a subquery in my check constraint to quickly resolve this issue. This is not possible with Oracle.

Is my mistake that this column has no business being in the icon_associations table? If not where should it go? Is this a case where, in Oracle, the constraint can only be handled with a trigger?

I ask only because I’d like to go the constraint route if at all possible.

Thanks so much for your help,
Paul

  • 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-19T00:29:55+00:00Added an answer on May 19, 2026 at 12:29 am

    One simple way that I believe solves your issue is to have another table called

    icon_default_associations (widget_type_id, icon_id)
    

    and simply make (widget_type_id, icon_id) obey a UNIQUE constraint (or make it the primary key).

    I think you’re overloading the purpose of icon_associations if you do it the way you’re attempting.

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

Sidebar

Related Questions

I had a hard time formulating the title, so please edit it if you
I've had a hard time trying to find good examples of how to manage
I have a malformed page to scrape, and have had a hard time getting
I've never really had the need to use any drag functions until now, so
As a mostly self-taught programmer, I have never really had anyone explain why certain
I'm really asking this by proxy, another team at work has had a change
Really simple question - how do I do a search to find all records
Really my question has more to do with the server-side scrubbing of html that's
I really feel that I should learn Lisp and there are plenty of good
Really stuck on trying to write code to unzip a file or directory on

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.