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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:36:00+00:00 2026-05-11T20:36:00+00:00

I have two tables users and lead_contacts which have similar data. When somebody buys

  • 0

I have two tables users and lead_contacts which have similar data. When somebody buys a product they become a user. How should I modify the two create staements below so:

  • that the leads table receives a new
    entry with first_name, last_name, company and email, when a user is created.
  • the first_name, last_name, company and email in users table is updated
    automatically when the leads table info is changed

    CREATE TABLE lead_contacts (
    contact_id int(11) NOT NULL auto_increment,
    user_id int(11) unsigned NOT NULL default ‘0’,
    email varchar(100) NOT NULL default ”,
    company varchar(50) NOT NULL default ”,
    first_name varchar(50) NOT NULL default ”,
    last_name varchar(50) NOT NULL default ”,
    address varchar(100) NOT NULL default ”,
    address_2 varchar(100) NOT NULL default ”,
    city varchar(50) NOT NULL default ”,
    state varchar(50) NOT NULL default ”,
    country varchar(50) NOT NULL default ”,
    postal_code varchar(30) NOT NULL default ”,
    phone varchar(30) NOT NULL default ”,
    fax varchar(30) NOT NULL default ”,
    ship_bill_same enum(‘Y’, ‘N’) NOT NULL default ‘Y’,
    notes text NOT NULL,
    admin_notes text NOT NULL,
    list_name varchar(50) NOT NULL default ”,
    lead_list int(11) unsigned NOT NULL default ‘0’,
    is_master_list enum(‘N’, ‘Y’) NOT NULL default ‘N’,
    active_work enum(‘Y’, ‘N’) NOT NULL default ‘Y’,
    parentID int(11) unsigned NOT NULL default ‘0’,
    PRIMARY KEY (contact_id),
    KEY user_id (user_id),
    KEY lead_list (lead_list),
    KEY is_master_list (is_master_list),
    KEY active_work (active_work),
    KEY parentID (parentID)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 PACK_KEYS=1;

    CREATE TABLE users (
    userID int(11) NOT NULL auto_increment,
    access_level int(11) NOT NULL default ‘0’,
    username varchar(100) NOT NULL default ”,
    password varchar(100) NOT NULL default ”,
    first_name varchar(50) NOT NULL default ”,
    last_name varchar(50) NOT NULL default ”,
    company varchar(100) NOT NULL default ”,
    email varchar(100) NOT NULL default ”,
    PRIMARY KEY (userID),
    UNIQUE KEY username (username)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;

  • 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-11T20:36:00+00:00Added an answer on May 11, 2026 at 8:36 pm

    I think you misunderstand how foreign keys work.

    A reference from leads to users means that a row must already exist in users before a row in leads can reference it.

    There’s no way in SQL to make a dependent table automatically create a row in its parent table on demand.

    You could do this with a trigger, I suppose. But not a foreign key constraints. Besides, the values to fill into the parent table must come from somewhere. Either you need to specify them in an INSERT statement in your application or in a trigger, or else use the defaults defined for each column in the users table. Given that you have a unique constraint on users.username, I don’t think this would be possible from a trigger.


    Re: your followup question in the comment:

    No, a foreign key can’t do what you’re describing. When you modify info in the leads table (the table with the foreign key), the only thing a foreign key can do is prevent the modification if you try to change the leads.user_id column to a value that is not found in the users table.

    The foreign key in the child (leads) table can’t change anything in the parent (users) table.

    I’m not sure what is the source of your mistaken understanding. Did you read it somewhere or see someone do something like this?

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

Sidebar

Related Questions

I have two tables: Users and Profiles. A user may have a profile and
I have two tables: Users and Roles. A user may have more roles, so
I'm using SQL-Server 2005. I have two tables Users and Payments which has a
I have two tables users registered_members I want to confirm values from user table
I have two tables: users: user_id user_name data: user_id user_data user_time I wan to
In my application I have two tables: Users and Profiles. A user has a
I currently have two tables similar to users and programs that are linked through
I have two Tables: Users and Permission. They share 2 columns with the same
I have two tables, users and groups . A user can belong to many
I have two tables Users and Companies: public class User { // Properties public

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.