in Technology by
How can we temporarily disable a foreign key constraint in MySQL?

1 Answer

0 votes
by

Try DISABLE KEYS or

SET FOREIGN_KEY_CHECKS=0;

Make sure to

SET FOREIGN_KEY_CHECKS=1;

after.

OR you can do this also

To turn off foreign key constraint globally, do the following:

SET GLOBAL FOREIGN_KEY_CHECKS=0;

and remember to set it back when you are done

SET GLOBAL FOREIGN_KEY_CHECKS=1;

WARNING: You should only do this when you are doing single user mode maintenance. As it might resulted in data inconsistency. For example, it will be very helpful when you are uploading large amount of data using a mysqldump output.

Related questions

0 votes
    I am using Laravel 5.7 version. I got the below error for users_activations table while run the command ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am using Laravel 5.7 version. I got the below error for users_activations table while run the command ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    How can we stop a scheduled job from being executed temporarily?...
asked Jul 16, 2021 by JackTerrance
0 votes
0 votes
    I have the following models: class Project(models.Model): name = models.CharField(max_length=300, unique= ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I'm using EF code first. By convention, I have added a foreign key and a reference to the foreign ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I'm trying to add foreign key in my table exam: public function up() { Schema::create('exams', ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Suggestions needed for creating better and efficient search indexes for models having foreign key and many-to-many ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    5. Which key defines a relationship between two tables? (a) Primary key (b) Foreign key (b) Secondary key (d) ... Full form of RDBMS is Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    What is the correct definition of foreign key? The common field of two tables. A field that contains unique data ... of another table. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    What is the correct definition of foreign key? The common field of two tables. A field that contains unique data ... of another table. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    In the above DDL command the foreign key entries are got by using the keyword (a) References (b) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    In the section relation which of the following is used as a foreign key? (a) Course_id (b) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    How can we stop Slow Query Log in MySQL?...
asked Aug 20, 2021 in Technology by JackTerrance
0 votes
    What MySQL property is used to create a surrogate key in MySQL? (a) UNIQUE (b) SEQUENCE (c) ... and JSP topic in section Database Programming Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
...