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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:04:45+00:00 2026-05-29T09:04:45+00:00

I need to update the primary ID value of a record in table_1 and

  • 0

I need to update the primary ID value of a record in table_1 and at the same time update the foreign keys referencing that ID value. In the sql below, i have included ALL the tables referencing table_1, however not all of these tables are referencing that particular record.
I am using the sql below:

UPDATE table_1 T1, 
table_2 T2, 
table_3 T3, 
table_4 T4,
table_5 T5, 
table_6 T6,
table_7 T7
SET T1.EMI_ID = 15678, 
    T2.AKN_EMI_FK = 15678, 
    T3.EXP_EMI_FK = 15678,
    T4.HDR_EMI_FK = 15678, 
    T5.LSU_EMI_FK = 15678,
    T6.MUT_EMI_FK = 15678, 
    T7.IMG_EMI_FK = 15678
WHERE T1.EMI_ID = 77777718765 AND 
T2.AKN_EMI_FK = T1.EMI_ID AND 
T3.EXP_EMI_FK = T1.EMI_ID AND 
T4.HDR_EMI_FK = T1.EMI_ID AND 
T5.LSU_EMI_FK = T1.EMI_ID AND 
T6.MUT_EMI_FK = T1.EMI_ID AND 
T7.IMG_EMI_FK = T1.EMI_ID; 

It does not seem to be working and i believe that could be because in some tables that record id does not exist as foreign key.

Is there a better way of doing this?

  • 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-29T09:04:46+00:00Added an answer on May 29, 2026 at 9:04 am

    Yes, by using a foreign key UPDATE constraint:
    http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

    Example:

    CREATE TABLE parent (id INT NOT NULL,
                         PRIMARY KEY (id)
    ) ENGINE=INNODB;
    CREATE TABLE child (id INT, parent_id INT,
                        INDEX par_ind (parent_id),
                        FOREIGN KEY (parent_id) REFERENCES parent(id)
                          ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=INNODB;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to update the primary key for a record but it's also the
I have an update statement that works fine but takes a very long time
I have an on update trigger in SQL Server 2008. I only need to
I have a table that stores two foreign keys, implementing a n:m relationship. One
I need to update time info in a DateTime. I get a string in
I need to update a record in the datastore, but instead of updated record
Do I really need to check that the the record in another table really
We have a massive table where I need to make an update on a
I have a number of tables I need to convert from mySQL to SQL
I have a situation where I need to ensure that there is only one

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.