project table
proj_id, proj_name, Proj_Type
1, test, dev
2, test1, infra
3, test2, BI
quota table
quota_id, proj_id, allot_type, allot_num
1, 1, java, 3
2, 1, architect, 1
3, 1, Jasper, 2
4, 2, unix admin, 2
5, 2, dba, 1
6, 2, nwk admin, 1
tracking table
track_id, proj_id, status,start_date, sch_end_date,end_date, update_date
1,1, started,dec 16 2012,feb 12 2013,,01 jan 2013
2,2, resource allocated, 01 jan 2013, 03 mar 2013, , 01 jan 2013
3,3, yet to start, 19 jan 2013, 19 apr 2013
Destination table (Summary_Table)
event_id, proj_id, proj_name, Proj_Type, allot_type, allow_num, proj_start_date_sch_end_date, proj_status
1, 1, test,dev,java,3,16 dec 2012,12 feb 2013,started
2, 1, test,dev,architect,1,16 dec 2012, 12 feb 2013, started
3, 1, test,dev,jasper, 2, 16 dec 2012, 12 feb 2013, started
I have to write a stored procedure to load the destination table with the information from all three source tables
and another procedure to update the records regularly in destination table when ever there is a change in source tables such as project status changed from started to delivered etc.
Can some one give me some sample procedures to achieve above please.
Load destination table
Or for each insert in any of the three sources table will have to insert in destination table too?
Just for loading just use a stored procedure
INSERT INTO desitination ([columns])
SELECT [columns]
FROM project
JOIN quota ON …
JOIN tracking ON …
For your second procedure – update destination table if there are any changes in source table, i would suggest to use triggers on update i.e.
(http://dev.mysql.com/doc/refman/5.0/en/triggers.html)
If you have to fill destination table each time when insert occurred in one of the source tables than will have to set a trigger for insert and update.
If the inserts/updates are not at the db level, like you have any application that is interacting with db, then setting a stored procedure to handle updates on destination table might work.
If you will provide the tables schema and some dummy data i can create a sample code.
http://sqlfiddle.com/#!8/43c77/1
Here is the sample code – but i do have a question – why using destination table i.e. have a table, why you are not using a view instead?