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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:13:42+00:00 2026-06-06T20:13:42+00:00

I’m a complete beginner to SQL and I am struggling to find a solution

  • 0

I’m a complete beginner to SQL and I am struggling to find a solution to a pretty simple problem.

The scenario is this: When a user registers on my site they are inserted into a ‘users’ table with only a few columns(user_id, username, email, password, date).

I don’t want to ask anymore of them when they register, however I would like each user to have an optional settings page where they can input additional user info such as forename, surname, bio etc.

To try and keep my database clean I have created a second table called ‘user_info’ for this info. This table includes the ‘user_id’ column that exists in ‘users’.

What I am struggling with is linking these two tables. I want it so whenever a user is added to the ‘users’ table a new entry is inserted into ‘user_info’ with the same ‘user_id’. This also needs to work for deletion of users.

So far I have gathered that the use of a FOREIGN KEY is required and have attempted to use CASCADE to solve this.

My tables look like this:

CREATE TABLE users (
user_id INT AUTO_INCREMENT NOT NULL,
username VARCHAR(20) NOT NULL default '',
email VARCHAR(100) NOT NULL default '',  
password VARCHAR(100) NOT NULL default '',
create_date DATETIME NOT NULL default '0000-00-00',
PRIMARY KEY (user_id),
UNIQUE KEY (username),
UNIQUE KEY (email)
);

CREATE TABLE user_info (
    user_id INT NOT NULL,
    forename VARCHAR(30) NOT NULL default '',
    surname VARCHAR(30) NOT NULL default '',
    dob DATE NOT NULL default '0000-00-00',
    location VARCHAR(30) NOT NULL default '',
    PRIMARY KEY (user_id),
    FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE ON UPDATE CASCADE
);

I would appreciate any advice in this issue, along with any advice on general best practice!

Kind Regards

Adam

  • 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-06T20:13:45+00:00Added an answer on June 6, 2026 at 8:13 pm

    I am also just a beginner at sql and the solution provided by me might not be the best. You can deal with this problem in two ways

    • Finding the last inserted id in your users table and then inserting a blank record in the user_info with the fetched id.

      Since your User ID is primary key, simply do this everytime when you insert:

    SELECT max(USER_ID) FROM users

    store the fetched result in a variable and then insert the value of variable in the user_info table

    INSERT INTO user_info (user_id) VALUES (‘.$theValueInTHeVariable.’);

    • The second method is by using triggers

    in this solution you can make a trigger so that whenever a new id is inserted into the users table it automatically fetches the last generated user_id and insert it into the Users_info table.

    for more information on triggers refer to the following sits.

    link1
    link2

    If you still face any problem then please post back.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.