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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:02:23+00:00 2026-05-27T17:02:23+00:00

My database is MySQL with foreign key management. It has 2 tables : Table1

  • 0

My database is MySQL with foreign key management. It has 2 tables :

Table1 :
|id|foreignKeyToTable2|data...|

Table2 : 
|id|foreignKeyToTable1|data...|

I want to delete a couple of these lines but when I delete one of them I have the meaningful foreign key error.

How can I delete the couple of lines in one time?

Am I forced to disable foreign key checks?

Edit : Problem with delete cascade

I need both of the keys because there is actually 2 relations. Lets be more practical :

  • the table 1 is a “drop down list” that has a default value.
  • the table 2 has every values possible for each DDL in table 1.

Tables are :

DDL
|id|name|defaultValue (FK delete cascade)|
Value
|id|name|DDLiD (FK)|

Following your answers, I added a DELETE CASCADE to the DDL table. But I still have a FK error .

Cannot delete or update a parent row: a foreign key constraint fails (Value, CONSTRAINT fk_Value_DDL FOREIGN KEY (DDL) REFERENCES DDL (id) ON DELETE NO ACTION ON UPDATE NO ACTION)

I don’t want to add a delete cascade on the Value table because i want to be able to delete a value.

  • 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-27T17:02:24+00:00Added an answer on May 27, 2026 at 5:02 pm

    You have two options here:

    1. Alter the foreign key definition to also delete referenced rows.
      This can be done with ON DELETE CASCADE.
    2. Use a transaction around the two delete statements.

    The second option is my prefered one, because a database user is informed about the usage in the other table and can then decide to use a transaction to remove data from both rows.

    Also, one usage scenario of a 1:1 relation is to allow different permissions on both tables. When using delete cascade I don’t know if these are checked.

    EDIT

    After I was pointed that MySQL is handling foreign key checking not as stated in the SQL standards, my second option is changed to:

    2.
    Because MySQL does not support deferred checking of foreign key constraints while using transactions (this is a deviation from SQL standards), you need to disable foreign key checks for the delete statements:

        SET foreign_key_checks = 0;
        DELETE ...;
        SET foreign_key_checks = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a new mysql database and i want to use foreign keys with
I use Hibernate/Spring and a MySQL Database for my data management. Currently I display
Is it possible to reference (InnoDB) a foreign key in another database in MySQL?
I need to make a small database in MySQL that has two tables. Clothes
I'm reorganizing our MySQL database, changing MyISAM tables to InnoDB and setting foreign keys,
We have a MySQL database that has two tables, Warehouse and Crate Warehouse: WarehouseID
Doing my first tryouts with foreign keys in a mySQL database and are trying
I have 10 tables in my database(MySQL). two of them is given below tbl_state
i have a mysql database: /* MySQL Data Transfer Source Host: 10.0.0.5 Source Database:
I have three tables in a MySQL database used in a music library application:

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.