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

  • Home
  • SEARCH
  • 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 8484869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:29:19+00:00 2026-06-10T20:29:19+00:00

I want to add something to a table (trigger?) so that, for exactly, exactly

  • 0

I want to add something to a table (trigger?) so that, for exactly, exactly 1 row per ID has a specific value for a specific column. So that if a statement was run that makes this not the case, an exception would be thrown and the insert would be rolled back.

Let’s take this schema.

ID    Current    Value
1     Y          0
1     N          0
1     N          2
2     Y          2

And the constraint I want is that for each ID, exactly one row has a current of ‘Y’.

Therefore, these statements would not be executed and return an appropriate error:

insert into table values (1,'Y',1);
insert into table values (3,'N',2);
update table set current = 'N' where ID = 1;

I have two questions:

  1. Is it a good idea to code this kind of constraint logic into your table, or is that best saved for the applications that manipulate the data? Why?

  2. How can it be done? What kind of tool does oracle provide to create a constraint like this?

  • 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-10T20:29:20+00:00Added an answer on June 10, 2026 at 8:29 pm

    It’s best if you can specify it in a declarative fashion (rather than procedurally, e.g. using triggers). Especially because triggers, without some kind of locking algorithm, will NOT work anyway due to concurrent sessions trying to insert/update the table at the same time.

    In this instance, the simplest solution is a unique, function-based index, e.g.:

    CREATE UNIQUE INDEX only_one_current ON thetable
      (CASE WHEN Current = 'Y' THEN ID END);
    

    The expression is NULL if Current = ‘N’, and all-NULL rows in an index are not stored, which means that the uniqueness constraint will only apply to rows where Current = ‘Y’.

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

Sidebar

Related Questions

In my sql server table, I want to add a computed column that is
I want to dynamically add links to my pages something like this: foreach (Node
I want to achieve something like the following: UrlBuilder ub = new UrlBuilder(http://www.google.com/search); ub.Parameters.Add(q,request);
I want add label to every row in tableview at right side of the
I want add my custom sidebar next right column all page. Please check this
I have a list of string values that I want add to a hashtable
My code is below. I want to add space between cells in tableCell() something
I want to add sorting to a HTML table populated by Hibernate. The actual
I have a table: Hourly_Sales that is like this (counting how many buy something
So my problem is that I want to add an event handler to a

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.