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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:54:20+00:00 2026-06-07T13:54:20+00:00

I have two separate tables already created and filled with info. The first table

  • 0

I have two separate tables already created and filled with info. The first table has a unique field called hostname. Each host name may have more than one record in the second table. I already created them and the hostname is inserted in both tables. Now, how can I connect them?

I’m using MySQL workbench. I have to create foriegn key in table2, and this key should be the hostname. Now if I want to insert in table2 before inserting into table1. Is this possible? i.e, my program run in a way that it inserts the information of table2 before table1. Is there any change in the insert statement? Do I have to specify anything about table1 when inserting 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-07T13:54:21+00:00Added an answer on June 7, 2026 at 1:54 pm

    If you have a foreign key, it must always reference a valid record or be NULL. If you need to insert into table2 before table1, you must first insert the table2 record with the foreign-key column NULL, then insert the table1 record, and finally update the table2 record with the reference to table1.

    It’s an odd analogy, but think of it like building a house. If you build it on-site before laying the foundation, you have a problem. But, you can build it somewhere, then build the foundation, then move the house onto it.

    Now, on a side note, I do have to question why you are inserting table2 before table1…

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

Sidebar

Related Questions

I have a view table which is a union of two separate tables (say
I have two tables, one table has a list of videos, one has a
I have two tables that have already been created. Document and DocumentStyle . They
I have a report with two separate tables referencing two separate datasets. The first
I have a table called WorkItemNotes, and separate tables for Customers and Employees. I
I have two separate sets of tables in the same database that model the
I have a list of addresses in two separate tables that are slightly off
I have a query which searches two separate fields in the same table... looking
I have two tables, 'user' and 'account' with a 1:1 relationship. account has a
I have two separate tables both with user id columns uid . I want

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.