Note: If we have two or more revision, and we want to delete an existing revision and also want to rename another one.

eg: delete Revision 0  and rename Revision A as Revision 0


Goes through following tables,

1. instrum
==========
select * from instrum where instr_id='DTL-9_B' and revision='0'
delete from instrum where instr_id='DTL-9_B' and revision='0'
update instrum set revision='0' where instr_id='DTL-9_B' and revision='A'


2. revision_historiestbl
========================
select * from revision_historiestbl where instr_id='DTL-9_B'
delete from revision_historiestbl where instr_id='DTL-9_B'


3. key2idstbl
=============
select * from key2idstbl where instr_id='DTL-9_B'
update key2idstbl set revision='0' where instr_id='DTL-9_B'


4. calibration table
====================
select * from cal_1_1_tm_default where instr_id='DTL-9_B' and revision='0'
delete from cal_1_1_tm_default where instr_id='DTL-9_B' and revision='0'
update cal_1_1_tm_default set revision='0' where instr_id='DTL-9_B'

5. instr_idstbl
===============
select * from instr_idstbl where instr_id='DTL-9_B'
update instr_idstbl set revision='0' where instr_id='DTL-9_B'


6. pdata
========
select * from pdata where instr_id='DTL-9_B' and revision='0'
delete from pdata where instr_id='DTL-9_B' and revision='0'
select * from pdata where instr_id='DTL-9_B' and revision='A'
update pdata set revision='0' where instr_id='DTL-9_B' and revision='A'


7. mydata
=========
select * from mydata where instr_id='DTL-9_B'
update mydata set revision='0' where instr_id='DTL-9_B'



Recalculation for that perticular instrument
============================================

select p.raw_file_ID,p.instr_id,p.taken_on,0,p.instrument_ID,p.level,p.data1,p.data2,p.data3,p.data4,p.data5,p.data6,p.remarks,p.pdata_ID,p.user_id,p.dm_data_source,'NEW', im.type1 as instr_type, im.subtype1 as instr_sub_type  from pdata as p
                    LEFT JOIN instrum im on im.instr_id = p.instr_id AND im.revision = p.revision
                    where   p.instr_id='DTL-9_B' and record_status='LIVE'



INSERT INTO raw_file_data_stack (raw_file_ID,instr_id,taken_on,revision,instrument_ID,level,data1,data2,data3,data4,data5,data6,remarks,pdata_ref,user,dm_data_source,data_choices, instr_type, instr_sub_type)
select p.raw_file_ID,p.instr_id,p.taken_on,0,p.instrument_ID,p.level,p.data1,p.data2,p.data3,p.data4,p.data5,p.data6,p.remarks,p.pdata_ID,p.user_id,p.dm_data_source,'NEW', im.type1 as instr_type, im.subtype1 as instr_sub_type  from pdata as p
                    LEFT JOIN instrum im on im.instr_id = p.instr_id AND im.revision = p.revision
                    where   p.instr_id='DTL-9_B' and record_status='LIVE'