pritam79 Posted November 5, 2011 Share Posted November 5, 2011 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 More sharing options...
Ingolme Posted November 5, 2011 Share Posted November 5, 2011 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.