Here's my procedure:
PROCEDURE add_values
AS
BEGIN
INSERT INTO TABLE_A ...
SELECT t.id, t.name FROM TABLE_C ("This selection will return multiple records")
END
While it inserts in TableA, I would like insert into another table(TableB) for that particular record which got inserted in tableA.
The columns in TableA and TableB are different. Is it wise to call a function before inserting into TableB - I would like to perform certain gets and sets based on the id inserted in tableA?
you can create a trigger to do it, if this is the only way you insert data into the table. (otherwise it will run on every insert)
or you can iterate on a cursor which will enable you to do it with every insert from the selection
(Cursor example
Try this
Inputs
Query
Output: [ For both table A & B]
id name
Basically I am inserting those records into TableA from TableC whose id's are even. And then by using Output clause inserting the values from TableA to TableB
For more information OUTPUT Clause
Hope this makes sense
The best technique depends on the details of your table definitions and the associated queries. Based on the info in your question, maybe something like this:
In MySQL try
INSERT..SELECT
, like this:http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-select-into-table.html