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

  • Home
  • SEARCH
  • 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 7407777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:47:05+00:00 2026-05-29T05:47:05+00:00

For example: Table 1 : user_ID – username – first_name – email – Table

  • 0

For example:

Table 1:

user_ID - 
username -
first_name -
email -

Table 2:

message_ID - 
user_ID - 
message_title -
message_body - 

As you can see I have user_ID as primary key in table 1, and as foreign key in the second table.

If I enter 2 rows into the first table, eg.

1, undergz, sarah, sarah@hotmail.com
2, michel21, michaele, michalzost@gmail.com

And now, michaele enters the message, and I now I add this to table 2:

1, 2, hello, hello everybody, 

I added this entry in the table 2 considering first table, I added user_ID number the same as in the table 1.

I did this from $_SESSION['user_ID'] variable, when I entered the second query. So it was like

INSERT INTO table_2 VALUES (NULL, {$_SESSION['user_id']}, '$title','$message') 

My question is, is this the right way to do this? We define foreign key in table so we enter data STRICTLY according to primary key, it must be the same for all values?

  • 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-29T05:47:07+00:00Added an answer on May 29, 2026 at 5:47 am

    The question you should ask yourself is:

    Can a row in the table 2 exist without a corresponding row in the table 1?

    If the answer to your question is “no”, then you need the FOREIGN KEY (a.k.a. referential integrity) constraint from table 2 (“child”) to table 1 (“parent”). You can think of it as having a “pointer” from one row to another, where the DBMS itself guarantees you can never have a “dangling” pointer.

    The “parent” set of columns in the FOREIGN KEY must always be the key, be it primary or alternate (a.k.a. UNIQUE). The “child” can be any column or combination of columns, whether they are part of a key or not. You can think of that as the parent’s key columns being propagated to the child, and depending on where the propagated columns end up, you can have the following 2 kinds of relationships:

    1) “Identifying” Relationship

    The parent key becomes a part of the child key (so parent “helps” identify the child):

    identifying relationship or identifying relationship

    This models either 1:N or 1:1 relationship.

    2) “Non-Identifying” Relationship

    The parent key does not become the part of the child’s key:

    non-identifying relationship

    This models 1:N relationship, but requires message_ID to be unique on its own (instead of in combination with user_ID).

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

Sidebar

Related Questions

I have a table similar to this: CREATE TABLE example ( id integer primary
I have three records in a table example: *Usernames* *email* *city* Nick nick@example.com London
I have the following tables (and example values): **user:** user_id (1, 2, 3) username
I have a SQL table like so: Update: I'm changing the example table as
In my database I have tables that define types for example Table: Publication Types
I have two tables, for example: Table A Table B ======= ======= Name |
How can I concatenate two char columns within a perform screen? example: table sample
I have a table with the following sample data: id user_id rank date_promoted 1
I have the following MySql table (user_actions) with the following columns: id, user_id, created_at,
How can I show my all blog post with images? Example: Mysql table: post_id

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.