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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:05:52+00:00 2026-06-03T05:05:52+00:00

I have two tables, TABLE_1 and TABLE_2 . TABLE_1 contains ID and NAME ,

  • 0

I have two tables, TABLE_1 and TABLE_2.

TABLE_1 contains ID and NAME, where ID is a primary key.

TABLE_2 contains ID and DATA, where ID and DATA form a compound primary key.

  1. I’m looking for a SQL query that updates the ID in TABLE_2 when they are changed in TABLE_1.

  2. How can I create this table structure?

TABLE_1

ID      NAME
100     LLL
101     KKK
102     JJJ

TABLE_2

ID      DATA
100     HHHHHHH
100     MMMMMMM
100     ZZZZZZZ
101     IIIIIII
101     FFFFFFF
102     EEEEEEE

Thank you for your help.

  • 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-03T05:05:54+00:00Added an answer on June 3, 2026 at 5:05 am

    Not sure why you need to do this, but anyway.

    One way to do this is to use foreign key constraints, available in the InnoDB storage engine:

    CREATE TABLE `TABLE_1` (
      `ID` int NOT NULL,
      `NAME` varchar(255) NOT NULL,
      PRIMARY KEY (`ID`)
    ) ENGINE=InnoDB;
    
    CREATE TABLE `TABLE_2` (
      `ID` int(11) NOT NULL,
      `DATA` varchar(255) NOT NULL,
      PRIMARY KEY (`ID`,`DATA`),
      CONSTRAINT `FK_ID` FOREIGN KEY (`ID`) 
        REFERENCES `TABLE_1` (`ID`) 
        ON UPDATE CASCADE
        ON DELETE CASCADE
    ) ENGINE=InnoDB;
    

    The above table structure will update all the matching ID from TABLE_2 whenever an ID in TABLE_1 is modified (ON UPDATE CASCADE). Also, whenever you delete an ID from TABLE_1, all the matching entries from TABLE_2 will also be deleted (ON DELETE CASCADE). Because of this constraint, the ID from TABLE_2 has to exist in TABLE_1 for an INSERT to complete successfully.

    Also keep in mind that foreign keys affect performance, but without knowing exactly why you want such a thing, I cannot suggest any better solution.

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

Sidebar

Related Questions

Into I have two tables profile and name , the profile table contains some
I have two tables containing peoples data, first name, last name etc. The first
I have these two tables: Table: ORDERS ID - NAME - DATA --------------------------------------------- 1
I have Two tables. 1.Users table (Username , Name) 2.Picture table( ID , Username
I have the following two tables: Table1 ---------- ID Name 1 A 2 B
I have two tables with the same structure: id name 1 Merry 2 Mike
I have two tables, one that contains nodes and second that contains the relationships
I have two tables: one contains employees information and another is transactions (sales) information
I have two tables: who contains these fields: gmdc_employee file_id company_id employee_id employee_name file_description
I have a table that contains two columns ID | Name ---------------- 1 |

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.