不想用递增,怕有一天记录过多超出范围会出错你用bigint做增量列的类型从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。存储大小为 8 个字节。
解决方案 »
- 请问怎么求sql时间间隔
- 討論帖--MSSQL日期類型
- 存储过程int参数问题
- 存储过程访问ODBC问题
- Access 2000 移植到 SQL Server 2000 的问题
- 重分求Sqlserver 2000英文版 ?在線等﹐立即給分!!!!!!!!!!!!!!!!!!!!
- 从一张中的相关数据插入到另一张表中
- 取字段的问题,大家帮忙看看有什么好办法?
- Delphi+Ado+SQL Server 存储过程,高手请进。
- oracle
- 熟ADO的请看!存储过程里有了insert语句后在应用程序里不能返回output值(sql里可以)
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~用Delphi的程序调用DTS对于相同的条件,却每次返回不同的结果~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insert into @t values (1)
insert into @t values (2)
insert into @t values(3)
insert into @t values(4)
insert into @t values(6)
insert into @t values(7)
insert into @t values(8)
insert into @t values(10)
declare @n int,
@no int,
@no1 int
select @no=count(*) from @t
set @n=1
while @n<=@no
begin
select @no1= count(*) from @t where id=@n
if @no1=0
begin
select @n as 最小值
set @n=@no+1
end
else
begin
set @n=@n+1
end
end
select (select count(id)+1 from tablename where id<a.id)as ids,*
from tablename as a)as u
where ids<>id
where not exists(select 1 from table where id = a.id + 1)
aierong(皑婀瑢-数据库XML.NET联盟会局长) 结果不太对啊
你的做法基本上满足要求,但如果是删除了第一条记录,则没有机会使用这个记录的编号!
提点,现在作以下修正:
select (case when isnull((select min(id) as id from 物品 where 编号=1),0)=0 then 1 else isnull(min(编号),0)+1 end) as ID from 物品 a where not exists(select 1 from 物品 where 编号=a.编号+1)