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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:57:33+00:00 2026-06-15T09:57:33+00:00

I have 2 tables: id box_name hidden ————————— id item_name box_id hidden so the

  • 0

I have 2 tables:

id box_name hidden

---------------------------

id item_name box_id hidden

so the foreign key is box_id, if the box is deleted or updated it touches also the child items, but how can I make the same with the hidden fields, they are indexes with the same type int(11), if I hide some box, all the children are hidden, but how to hide only the children who references to the box_id -> id, those hidden???

or in other words, how to make 2 foreign keys

  • 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-15T09:57:35+00:00Added an answer on June 15, 2026 at 9:57 am

    You can easily do this by adding unique constraint on parent table id,hidden fields and changing your detail table so it has FK to (id,hidden) rather than to just id. However, in this case I don’t see why you need to store hidden attribute in detail table since it’s always the same as parent hidden.

    I’d rather add an after update trigger on master table that updates all necessary rows in detail table[s].

    Update. Example.
    1st approach

    CREATE TABLE boxTable(id int not null auto_increment primary key,hidden 
    tinyint not null,
    ...
    CONSTRAINT UQ_BOXTABLE(id,hidden));
    CREATE TABLE childTable(...., boxId int not null, hidden tinyint not null,
     CONSTRAINT FK_childTable_BoxTable FOREIGN KEY (boxId, hidden) REFERENCES 
     boxTable(boxId, hidden) ON DELETE CASCADE ON UPDATE CASCADE) ;
    

    every time you change hidden in boxTable it will be automatically updated in childTable.

    2nd approach (double check syntax, I don’t have mysql at the moment)

    CREATE TRIGGER AU_boxTable AFTER UPDATE ON boxTable 
    FOR EACH ROW
    BEGIN 
      IF (new.hidden <> old.hidden) THEN 
        update childTable set hidden = new.hidden WHERE boxId = new.id;
      END IF;
    END;
    

    2nd approach allows you changing hidden fields in childTable regardless of value in boxTable, the first doesn’t.

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

Sidebar

Related Questions

I have two tables, user and company, and I have a combo box in
I have two tables, employee as the parent and license as the child. They
I have two tables called calendar_colour and user, calendar_colour ( colour_id int primary key,
Suppose I have these tables create table bug ( id int primary key, name
I have two tables Employee and Department . I have joined with primary key
I have a table where each rows has a check box. This code works
I have a problem with building multi level select box. I have category table
In my table I have a column with a check box for each row.
I have a drop down box for each row inside a table <table> <tr>
I have a html element (like select box input field) in a table. Now

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.