Hello,
I wanted to know what would be the best way to update a field of a row while I am inserting. Here are the tables and fields (for simplicity I am only including relevant fields):
• firms
⁃ firm_id (integer, autoincrement, primary key)
⁃ firm_code (varchar(25), internal code)
⁃ name (varchar(100), firm name)
• offices
⁃ office_id (integer, autoincrement, primary key)
⁃ office_code (varchar(25), internal code)
⁃ firm_id (integer, foreign key to firms table, NOT NULL)
⁃ firm_code (varchar(25), internal code)
⁃ name (varchar(100), office name)
The firms data has already been loaded. What I want to do is as I load the data into the offices table, via LOAD TABLE command, I want to check the firm_code in the offices data against the firm_code in the firms table and update the firm_id while I perform the insert into the offices table.
I was thinking about writing a trigger to do that; however, since I have never written a trigger, I was not sure how to go about doing that via a trigger. Also, if there are better ways to achieve this, please let me know that as well.
Thank you in advance.
I wanted to know what would be the best way to update a field of a row while I am inserting. Here are the tables and fields (for simplicity I am only including relevant fields):
• firms
⁃ firm_id (integer, autoincrement, primary key)
⁃ firm_code (varchar(25), internal code)
⁃ name (varchar(100), firm name)
• offices
⁃ office_id (integer, autoincrement, primary key)
⁃ office_code (varchar(25), internal code)
⁃ firm_id (integer, foreign key to firms table, NOT NULL)
⁃ firm_code (varchar(25), internal code)
⁃ name (varchar(100), office name)
The firms data has already been loaded. What I want to do is as I load the data into the offices table, via LOAD TABLE command, I want to check the firm_code in the offices data against the firm_code in the firms table and update the firm_id while I perform the insert into the offices table.
I was thinking about writing a trigger to do that; however, since I have never written a trigger, I was not sure how to go about doing that via a trigger. Also, if there are better ways to achieve this, please let me know that as well.
Thank you in advance.