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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:52:43+00:00 2026-05-28T00:52:43+00:00

I wonder whether someone may be able to help me please. I’m wanting to

  • 0

I wonder whether someone may be able to help me please.

I’m wanting to use the ‘Delete Cascade’ mySQL functionality so that when a user is deleted from the ‘user details’ table, it deletes their records from the other tables in my database.

After reading through some posts on Stackoverflow and from research I’ve carried out on the Internet, I’ve changed my tables to InnoDB and started to change my existing tables.

I’ve been able to add the ‘Delete Cascade With Foreign Key’ to my first table, but when I try to do the same to any other table, I receive the following error:

#1005 - Can't create table './db369054642/#sql-30d_bd1a57.frm' (errno: 121)

But I’m not sure why I’m receiving this error because the first table that I changed worked without a hitch.

Could someone tell me please, are you only able to link the parent table to one child table?

Parent Table (User Details)

DROP TABLE IF EXISTS `userdetails`;
CREATE TABLE IF NOT EXISTS `userdetails` (
  `userid` int(6) NOT NULL auto_increment,
  `forename` varchar(20) NOT NULL,
  `surname` varchar(30) NOT NULL,
  `emailaddress` varchar(150) NOT NULL,
  `password` varchar(200) NOT NULL,
  `passwordhint` varchar(20) NOT NULL,
  `subscriptionexpiration` date NOT NULL,
  `salt` varchar(200) NOT NULL,
  PRIMARY KEY  (`userid`),
  UNIQUE KEY `emailaddress` (`emailaddress`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Child Table (detectors)

DROP TABLE IF EXISTS `detectors`;
CREATE TABLE IF NOT EXISTS `detectors` (
  `userid` int(6) NOT NULL,
  `detectorid` int(6) NOT NULL auto_increment,
  `detectorname` varchar(30) NOT NULL,
  PRIMARY KEY  (`detectorid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=0 AUTO_INCREMENT=1 ;

Delete Cascade SQL Statement

ALTER TABLE detectors
   add CONSTRAINT fk_userdetails
     FOREIGN KEY (userid)
     REFERENCES userdetails(userid)
     ON DELETE CASCADE
  • 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-05-28T00:52:44+00:00Added an answer on May 28, 2026 at 12:52 am

    Do both your table and the referenced table have indexes on the involved columns?

    From http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html:

    InnoDB requires indexes on foreign keys and referenced keys so that
    foreign key checks can be fast and not require a table scan. In the
    referencing table, there must be an index where the foreign key
    columns are listed as the first columns in the same order. Such an
    index is created on the referencing table automatically if it does not
    exist. (This is in contrast to some older versions, in which indexes
    had to be created explicitly or the creation of foreign key
    constraints would fail.) index_name, if given, is used as described
    previously.

    Try to create the necessary indexes first, or show us the output from the SHOW CREATE TABLE yourTableName so we can check if the indexes exist and have no name conflicts.

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

Sidebar

Related Questions

I wonder whether someone may be able to help me please. I currently use
I wonder whether someone may be able to help me please with a error
I wonder whether someone may be able to help me please. I'm trying to
I wonder whether someone may be able to help me please. I've put some
I wonder whether someone may be able to help me please. I've been working
I wonder whether someone may be able to help me please. I'm currently working
I wonder whether someone may be able to help me please. I am using
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I'm using the
I wonder whether someone may be able to help me please. I'm using the

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.