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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:56:17+00:00 2026-06-09T07:56:17+00:00

I am trying to delete a certain field from one table and I want

  • 0

I am trying to delete a certain field from one table and I want it to delete all the associated fields (ones containing the appropriate fk) from a different table.

Table1

      id | name | fname

Table 2

      id | table1Id | ...

The table1Id is set as a foreign key referencing the primary key of Table1 and I have set ON DELETE CASCADE

Now my code is simple and it deletes the row from Table1 like so:

function deleteWill($Id)
    {
        $stmt = $this->db->stmt_init();
        if($stmt->prepare('DELETE FROM Table1 where id= ?'))
        {
            $stmt->bind_param("i", $Id);
            $stmt->execute();
            $stmt->close();
            return true;
        }
        else
        {
            $stmt->close();
            return false;
        }
    }

However the CASCADE option doesnt work!

Does it have to do with the fact that I have multiple rows in Table2 that have the same fk?

If so how can I fix this so that it deletes all the associated rows in Table2?

  • 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-09T07:56:18+00:00Added an answer on June 9, 2026 at 7:56 am

    No, multiple rows in Table2 should not be a problem.

    There’s not enough information to determine what is causing the behavior you observe.
    If your statement is completing successfully, and the expected row is being removed from Table1, but the matching rows in Table2 are not being deleted…

    Then the first suspect is that your tables are using the MyISAM engine instead of the InnoDB engine. (MyISAM doesn’t enforce foreign key constraints, but InnoDB does.) The output from:

    SHOW CREATE TABLE Table1
    SHOW CREATE TABLE Table2
    

    will reveal which engine is being used. I’d start there. There are some other possibilities, such as verifying that foreign_key_check = 1;


    To change the engine for a table from MyISAM to InnoDB:

    ALTER TABLE Table1 ENGINE = InnoDB ;
    

    This will require a rebuild of the entire table; it basically needs to create a new InnoDB table and copy all of the data from the MyISAM table. So, don’t do this on a large table while it is being used…

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

Sidebar

Related Questions

I'm trying to delete all tables from a database except one, and I end
I'm trying to delete certain lines from a file. My file is a .txt
I am trying to make a schedule table that would delete certain rows according
I am trying to delete MySQL table rows from a Web page using Perl.
I'm trying to delete all rows in a table using Castle ActiveRecord. Normally, I
I am trying to delete certain key/value pairs from a hash, but I get
I keep getting these errors when trying to delete rows from a table. The
I am trying to delete a row from a table but i have three
I'm trying to record DELETE statements in a certain table using Oracle's auditing features.
I am trying to move certain lines from one .txt file to another. These

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.