Jump to content

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...