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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:20:45+00:00 2026-06-11T12:20:45+00:00

Two tables share a unique identifier ‘id’. Both tables are meant to be joined

  • 0

Two tables share a unique identifier ‘id’. Both tables are meant to be joined by using ‘id’.
Defining ‘id’ as an auto incrementing primary key in both tables may risk update inconsistencies.

Is there some general pattern to avoid such a situation or do I have to deal with updating table1 first and table2 by utilizing the last inserted id after (therefore not declaring id as auto inc 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-11T12:20:46+00:00Added an answer on June 11, 2026 at 12:20 pm

    First, if you use InnoDB table engine in MySQL you could use both transactions and foreign keys for data consistency.

    Second, after the insert in the first table, you could get the last insert id (depending on the way you access the db) and use it as foreign key.

    Eg
    Table 1: Users: user_id, username
    Table 2: User_Profiles: user_id, name, phone

    In User_Profiles you don’t need to define user_id as auto increment, but first insert a record in Users table and use the user_id for the User_Profiles record. If you do this in transaction, the Users record won’t be seen outside of the transaction connection until it’s completed, this way you guarantee that even if something bad happens after you insert the user, but before you have inserted the profile – there won’t be messed up data.

    You could also define that the user_id column in User_Profiles table is foreign key of Users table thus if someone deletes a record from the Users table, the database would automatically delete the one in User_Profiles. There are many other options – read more about that.

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

Sidebar

Related Questions

i've got two tables: members and members_data . They both share the same unique
I have two tables, Users and People, both of which share a common attribute,
I have two tables, one Master and one ExtraData. Both tables share columns FirstName,
I have two tables which share primary keys. I designed poorly, and it turns
Two tables: table_a ------- table_a_id: (primary, int) table_b ------- table_a_id: (index, int, from table_a)
I have two tables, each one has a primary ID column as key. I
if I have two tables: files(id, owner) and share(file_id, user) , where owner and
I have two tables which share common fields. Rather than re-map all of these
I have two tables record and share . record has columns: name and id
I have two tables, that share the same definition. I commonly insert new objects

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.