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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:07:22+00:00 2026-06-09T19:07:22+00:00

I have a question about how to update a field on cascade with a

  • 0

I have a question about how to update a field on cascade with a second field as constraint.

The structure is this (I removed the unnecessary columns):

Table nodes with columns idNode and idDimension (together they form the primary key).

Table forces with columns idForce (PK), idNode (foreign key to nodes.idNode) and idDimension.

Cascade update and delete on everything.

The problem in this structure that it seems to appear is this:

If in nodes I have an entry like (1, 1) and one like (1, 2) and in forces (1, 1, 1) and (1, 1, 2) and I update or delete first entry from nodes both entries in forces will be affected.

I need to affect only the one that also has the corresponding idDimension. How can I modify current structure to do that?

Edit: Tables – Nodes:

CREATE TABLE IF NOT EXISTS `nodes` (
  `idNode` varchar(11) NOT NULL,
  `idDimension` int(10) unsigned NOT NULL,
  `idNetwork` int(10) unsigned NOT NULL DEFAULT '0',
  `level` int(11) unsigned NOT NULL DEFAULT '0',
  `energy` bigint(20) DEFAULT NULL,
  `resources` bigint(20) unsigned NOT NULL DEFAULT '0',
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `name` varchar(20) DEFAULT NULL,
  `order` tinyint(3) DEFAULT '0' COMMENT 'energy 0\nassemble 1\nupgrade 2',
  `core` tinyint(1) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`idNode`,`idDimension`),
  KEY `network_dimension` (`idDimension`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Node table';

Forces:

 CREATE TABLE IF NOT EXISTS `forces` (
  `idForce` bigint(10) unsigned NOT NULL AUTO_INCREMENT,
  `idNode` varchar(11) NOT NULL,
  `idDimension` int(10) unsigned NOT NULL,
  `drones` bigint(20) DEFAULT NULL,
  `stance` tinyint(3) DEFAULT NULL COMMENT '0 - defense\n1 - neutral\n2 - attack      \n\nIf planet is parano and you are not allied to owner you can only be in attack.\n\nIf owner is allied you can only be in defense or neutral.\n\nIf you are owner you can only be in defense.',
   `order` tinyint(3) DEFAULT '0' COMMENT 'extract energy 1\nbuild node 2\nreplicate 3\nmove 4',
  `value` text,
   PRIMARY KEY (`idForce`),
   KEY `idNode` (`idNode`,`idDimension`),
   KEY `idDimension` (`idDimension`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

—

— Constraints for table forces

  ALTER TABLE `forces`
    ADD CONSTRAINT `forces_ibfk_2` FOREIGN KEY (`idDimension`) REFERENCES `nodes`  (`idDimension`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `fk_forces_nodes1` FOREIGN KEY (`idNode`, `idDimension`) REFERENCES `nodes` (`idNode`, `idDimension`) ON DELETE NO ACTION ON UPDATE NO ACTION,
    ADD CONSTRAINT `forces_ibfk_1` FOREIGN KEY (`idNode`) REFERENCES `nodes` (`idNode`) ON DELETE CASCADE ON UPDATE CASCADE;

My constraints are not working as I would like so feel free to ignore them :).

  • 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-09T19:07:23+00:00Added an answer on June 9, 2026 at 7:07 pm

    There are two strange foreign key (forces_ibfk_1 and forces_ibfk_2) which refers to non unique fields. Remove them –

    ALTER TABLE forces DROP FOREIGN KEY forces_ibfk_1;
    ALTER TABLE forces DROP FOREIGN KEY forces_ibfk_2;
    

    Then recreate fk_forces_nodes1 that refers to unique pair of fields with CASCADE action option –

    ALTER TABLE forces
      DROP FOREIGN KEY fk_forces_nodes1;
    
    ALTER TABLE orces
      ADD CONSTRAINT fk_forces_nodes1 FOREIGN KEY (idNode, idDimension)
        REFERENCES nodes(idNode, idDimension) ON DELETE CASCADE ON UPDATE CASCADE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about TSQL function Update. For example, I have a table
i have a question about the choices option field. i have this field: SECUENCIA
I have a question about using subqueries in an Update statement. My example: UPDATE
I have a question about Solr and the possibility to implement a customized update
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
QUESTION 1 I have to update some fields of a table of access according
I have a question about this error and hope someone has ran into it
I have a question about models on Ruby on Rails: I have this method
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass

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.