实际上,这两个表可以做到在一个系统中都主建立一个,每一个表中的一条记录对应类似你需要的一个ID。所以表很小。同时,回写程序最好使用存储过程,以减少锁定时间。同时需要注意:一旦取出记录,就要回写,即使不使用此ID,也不能再用!(可以再用的方法也有,有兴趣...)
CREATE PROCEDURE up_findid
@find_idmc char(12),
@return_id char(12) output,
@return_ws int output /*ID的位数*/
as
declare @li_i int
begin
select @return_id = Value,@return_ws = Digit from sys_code where CodeName = @find_idmc
if isnull(@return_id,'0') = '0'
begin
select @return_id = ''
select @return_ws = 0
end
else
begin
select @return_id = str(cast(@return_id as int) + 1)
update sys_Code set Value = @return_id where CodeName = @find_idmc
end
end
只是我在SQL SERVER 7中写的存储过程(与日期无关的)。在DELPHI中的调用你应该会!
参数@return_ws对应表中的一列,意思是你需要取的ID的位数。因为我前台需要将ID前需要补充‘0’,一保持所有ID位数相同!