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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:37:50+00:00 2026-06-02T14:37:50+00:00

CREATE TABLE `categories` ( `idcategories` INT NOT NULL AUTO_INCREMENT , `idparent` INT NULL ,

  • 0
CREATE  TABLE `categories` (
  `idcategories` INT NOT NULL AUTO_INCREMENT ,
  `idparent` INT NULL ,
  `description` VARCHAR(45) NULL ,
  PRIMARY KEY (`idcategories`) );

ALTER TABLE `categories` 
  ADD CONSTRAINT `FK_idparent`
  FOREIGN KEY (`idparent` )
  REFERENCES `ilmercatinodelpulcino`.`categories` (`idcategories` )
  ON DELETE CASCADE
  ON UPDATE CASCADE
, ADD INDEX `FK_idparent` (`idparent` ASC) ;

INSERT INTO `categories` (`idcategories`, `description`)
    VALUES (1, 'cat1');
INSERT INTO `categories` (`idcategories`, `idparent`, `description`)
    VALUES (2, 1, 'cat1_child');

So this table represents a category, with an ID and a self pointing parent ID.
I have inserted a category cat1 and a subcategory cat1_child with parent id of cat1.

Now, I want to be able to change idcategory of cat1 from 1 to 10 and because I set the foreign key on update CASCADE, I expect that idparent of cat1_child will be set to 10 as well.
But when I do:

UPDATE `categories` SET `idcategories`=10 WHERE `idcategories`='1';

I get an error:

ERROR 1451: Cannot delete or update a parent row: a foreign key
constraint fails (categories, CONSTRAINT FK_idparent FOREIGN KEY
(idparent) REFERENCES categories (idcategories) ON DELETE
CASCADE ON UPDATE CASCADE) SQL Statement: UPDATE categories SET
idcategories=10 WHERE idcategories=’1′

The delete instead work as expected and deleting cat1, cat1_child will be deleted as well.

Where is the error?
Than you.

  • 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-02T14:37:55+00:00Added an answer on June 2, 2026 at 2:37 pm

    I believe the answer is in the documentation (scroll down to the bottom):

    Deviation from SQL standards: If ON UPDATE CASCADE or ON UPDATE SET
    NULL
    recurses to update the same table it has previously updated
    during the cascade, it acts like RESTRICT. This means that you cannot
    use self-referential ON UPDATE CASCADE or ON UPDATE SET NULL
    operations. This is to prevent infinite loops resulting from cascaded
    updates. A self-referential ON DELETE SET NULL, on the other hand, is
    possible, as is a self-referential ON DELETE CASCADE. Cascading
    operations may not be nested more than 15 levels deep.

    Demo: http://www.sqlfiddle.com/#!2/e29db/1

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

Sidebar

Related Questions

create table snippet( id int not null auto_increment, primary key(id), idlanguage int not null,
create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
CREATE TABLE Posts { id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(200), url VARCHAR(200) }
CREATE TABLE `db`.`Complete` ( `CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
create table categories(a integer unsigned NOT NULL,b integer unsigned NOT NULL,primary key(a,b)); And create
Create Table: CREATE TABLE `category` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255)
CREATE TABLE `social_activity_stream` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `social_actor_id` int(11) NOT NULL, `social_activity_id`
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Two simple tables: CREATE TABLE categories( _id integer primary key autoincrement, name text not
CREATE TABLE SupplierQuote ( supplierQuoteID int identity (3504,2) CONSTRAINT supquoteid_pk PRIMARY KEY, PONumber int

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.