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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:05:12+00:00 2026-06-10T11:05:12+00:00

I have a requirement as mentioned below: table1 ———————— A B C D E

  • 0

I have a requirement as mentioned below:

table1
------------------------
A    B     C    D   E    
------------------------
1    2     *    P    Q
1    2     A    Q    P
1    3     B    W    U
-----------------------

Column A B C are the primary key on table1

table2
------------------------
A    B     C    
------------------------
1    2     1   
1    2     2   
1    2     A    
------------------------

column A B C needs to be implemented as composite foreign key on table2
for column A B C on table 1, the only exception is ,if column C in parent table (table 1) is *
then any value can appear in column C of child table (table2) provided column A and column B
are same in both tables.

We are looking for an implementation with minimal trigger .Currently we are not able to create foreign key because of this weird requirement.

Please suggest any alternate approach and make my day 🙂

  • 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-10T11:05:14+00:00Added an answer on June 10, 2026 at 11:05 am

    This issue can be addressed without need of any new structure.
    just by introducing a new_column (NEW_C) in child table (table2)
    and using this column in foreign key contraint instead of ‘column C’.
    Steps are below:

    1>alter table2 add (new_c varchar2(1));

    2>update table2 set new_c= c;

    3>Use newly introduced column NEW_C instead of colum C in FK

    alter table table2
      add constraint
      fk_ref_table1 FOREIGN KEY (A,B,**NEW_C**)    
      references table1 (A,B,C);
    

    4>Create a simple insert/update trigger on child table to maintain new column NEW_C.

    CREATE OR REPLACE maintain_new_c
     BEFORE
      INSERT OR UPDATE
      ON TABLE2 REFERENCING NEW AS NEW OLD AS OLD
     FOR EACH ROW
    DECLARE
    v_count pls_integer;
    BEGIN
     SELECT COUNT(1) 
       INTO v_count
       FROM table1 t1    
      WHERE t1.c='*'
        AND t1.a= :NEW.a 
        AND t1.b= :NEW.b;
    
      IF v_count=0 THEN
        new_c := :NEW.c ;
      ELSE
        new_c := '*';
      END IF;
    
    EXCEPTION
       WHEN OTHERS THEN
       RAISE_APPLICATION_ERROR..........
    END;
    

    Alternative is to introduce a new virtual column (oracle 11g) on child table,
    Use deterministic pl/sql function to
    derive this virtual coulmn and then create foreign key constraint
    using Virtual column.

    But I will prefer trigger based approach as any udate/delete operation on parent table
    will suffer because need to derive and check Virtual column each time.

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

Sidebar

Related Questions

I have a simple requirement as mentioned below: A ListView or any control displays
I have encountered a problem in that I already have a composite primary key
I have a database table like the one mentioned below. id | lecture |
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have requirement where some times I would like to load children as well
I have requirement to disable copy/paste/cut operations on a textbox. For this purpose I
I have requirement, wherein I have to calculate totals for cash and credit cards
I have requirement of specifying web part connections in onet.xml. So when site is
I have requirement as following like showing ABPeoplePickerNavigationController in tabbar based application. I researched
I have requirement to get Facebook friends list with their images. How can I

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.