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
  • 1 View
  • 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 coming up with a title for this question, but
I had an interview and a question that seems really simple was not clicking
really simple question, just having a hard time actually making it work. I have
Today I had a really hard time programming in ruby. I came upon this
I had a hard time formulating the title, so please edit it if you
I'm new to programming and have had a hard time understanding recursion. There's a
(Sorry if this is a repeat question, I had a hard time thinking of
Possible Duplicate: How to catch exceptions I have not really had to use try
I have had the following problem for a while and I am really not
I've got a really odd issue that I've not had any success googling for.

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.