multi-threading batch updates, how to get unique identifiers
create procedure My_unique
(
@table_id int,
@incr int,
@unique int output
)
as
/*
* %W% %D%
* Get a block of incr unique id's for table with ID table_id.
* Returns first ID in the block.
*/
select @unique = -999
if @incr < 1
begin
select error_status = "Must set increment > 0"
return @unique
end
if @table_id = 103
begin
begin transaction
update tradeControl
set tradeId = tradeId + @incr
select @unique = tradeId - @incr
from tradeControl
commit transaction
return @unique
end
else if @table_id = 100
begin
begin transaction
update STPIdCtrl
set id = id + @incr
where STPFieldName = 'eventId'
select @unique = id - @incr
from STPIdCtrl
where STPFieldName = 'eventId'
commit transaction
ret
urn @unique
end
else if @table_id = 101
begin
begin transaction
update STPIdCtrl
set id = id + @incr
where STPFieldName = 'ticketId'
select @unique = id - @incr
from STPIdCtrl
where STPFieldName = 'ticketId'
commit transaction
retu
rn @unique
end
else if @table_id = 104
begin
begin transaction
update STPIdCtrl
set id = id + @incr
where STPFieldName = 'updateId'
select @unique = id - @incr
from STPIdCtrl
where STPFieldName = 'updateId'
commit transaction
retur
n @unique
end
else if @table_id = 110
begin
begin transaction
update TDSIdCtl
set updateId = updateId + @incr
select @unique = updateId
from TDSIdCtl
commit transaction
return @unique
end
else if @table_id = 14
begin
begin transaction
select @uniq
ue = ord_grouping_id
from CDM_ord_groupings_ctrl holdlock
update CDM_ord_groupings_ctrl
set ord_grouping_id = ord_grouping_id + @incr
commit transaction
end
else if @table_id = 27
begin
begin transaction
select @unique = order_id
from CDM_order_ctrl holdlock
update CDM_order_ctrl
set order_id = order_id + @incr
commit transaction
end
else if @table_id = 28
begin
begin transaction
select @unique = execution_id
from CDM_execution_ctrl holdlock
update
CDM_execution_ctrl
set execution_id = execution_id + @incr
commit transaction
end
else if @table_id = 26
begin
begin transaction
update CDM_position_ctrl
set position_id = position_id + @incr
select @unique = position_id - @incr
from CDM_position_ctrl
commit transaction
end
else if @table_id = 18
begin
select @unique = volatility_id
from CDM_volatility_ctrl holdlock
update CDM_volatility_ctrl
set volatility_id = volatility_id + @incr
end
else if @table
_id = 20
begin
begin transaction
update CDM_yield_ctrl
set yield_id = yield_id + @incr
select @unique = yield_id - @incr
from CDM_yield_ctrl
commit transaction
end
else if @table_id = 22
begin
begin transaction
update CDM_divide
nd_ctrl
set dividend_id = dividend_id + @incr
select @unique = dividend_id - @incr
from CDM_dividend_ctrl
commit transaction
end
else if @table_id = 29
begin
begin transaction
update CDM_underlying_ctrl
set underlying_id = u
nderlying_id + @incr
select @unique = underlying_id - @incr
from CDM_underlying_ctrl
commit transaction
end
else if @table_id = 19 or @table_id = 102
begin
begin transaction
update CDM_yield_list_ctrl
set yield_list_id = yield_list_
id + @incr
select @unique = yield_list_id - @incr
from CDM_yield_list_ctrl
commit transaction
end
else if @table_id = 21
begin
begin transaction
update CDM_dividend_list_ctrl
set dividend_list_id = dividend_list_id + @incr
selec
t @unique = dividend_list_id - @incr
from CDM_dividend_list_ctrl
commit transaction
end
else if @table_id = 95
begin
begin transaction
update CDM_borrow_detail_ctrl
set borr_id = borr_id + @incr
select @unique = borr_id - @incr
from CDM_borrow_detail_ctrl
commit transaction
end
else if @table_id = 96
begin
begin transaction
update CDM_borrow_list_ctrl
set borr_list_id = borr_list_id + @incr
select @unique = borr_list_id - @incr
from CDM_borrow_list_ctrl
commit transaction
end
else if @table_id = 55
begin
select @unique = execution_log_id
from CDM_execution_log_ctrl holdlock
update CDM_execution_log_ctrl
set execution_log_id = execution_log_id + @incr
end
else if @table_id = 58
beg
in
select @unique = reut_mask_id
from CDM_reuters_masks_ctrl holdlock
update CDM_reuters_masks_ctrl
set reut_mask_id = reut_mask_id + @incr
end
return @unique
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.