各位大虾,我想做这样一个操作,不知可行否
当我后台往SQL Server里面插入数据的时候,比如我这一次往数据库里面插的有2条数据,那这个字段里面的值就为:一个6位数的自然序号 为:000001 当我第二次往数据库里面一次性插入3条数据数据时。对应这三条数据里面的字段为:000002
依次。。 这样能实现吗?
如果能,各位大虾给个方法,万分感激
当我后台往SQL Server里面插入数据的时候,比如我这一次往数据库里面插的有2条数据,那这个字段里面的值就为:一个6位数的自然序号 为:000001 当我第二次往数据库里面一次性插入3条数据数据时。对应这三条数据里面的字段为:000002
依次。。 这样能实现吗?
如果能,各位大虾给个方法,万分感激
id int identity,
ida int,
scode varchar(10),
data int
)create trigger tb_insert_y
on tb
for insert
as
begin
declare @ida int
select @ida=isnull(max(ida),0) from tb t
where not exists(select 1 from inserted where t.id=id)
update tb
set ida=@ida+1,scode=right(100000+@ida+1,5)
from tb t,inserted i
where t.id=i.id
end insert into tb(data)select id from tb_tmpselect * from tb