Jump to content
Sign in to follow this  
pritam79

Foreign Keys

Recommended Posts

Hi all,I have the following two tables in MySQL. When I insert a record in the ‘user-usr’ table, I want the foreign key ‘idusr_com’ to get inseted in the company_com table accordingly. What is the appropriate SQL statement to do so? Do I need two queries? What happens when I need to insert foreign key values in many tables at a time?1. company_com - to store the company main information. id_com - the primary key for the company table. No two companies can have the same ID. idusr_com - a foreign key to the company's entry in the users table below. Login and access restrictions are stored there. name_com - the company's name (Amazon, Best Buy etc.) address_com - stores the company address2. user_usr - stores the user data: e-mail, password etc. id_usr - the primary key for the user table. No two users can have the same ID. password_usr - stores user password. active_usr - a boolean variable (Y/N) based on whether the user account is active or not. level_usr - either a 1 or a 0 depending on whether the user is a company or an applicant.

Share this post


Link to post
Share on other sites

Normally, the idea of a foreign key is to point to a record that already exists. You'll need two queries to add records to two different tables.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...