表A的字段ID,是自加类型的
用sql语句怎么知道当前ID的最大值?,因为当中有些ID的记录可能被删除
比如表A的记录:
ID
1
2
其中3,4的记录删除拉,所以sql查找当前ID的最大值应该是4,这个语句怎么写?
用sql语句怎么知道当前ID的最大值?,因为当中有些ID的记录可能被删除
比如表A的记录:
ID
1
2
其中3,4的记录删除拉,所以sql查找当前ID的最大值应该是4,这个语句怎么写?
调试欢乐多
select @max=max(id ) from 表
这个方法查出来的是我要的结果,可是不知道怎么取,skyboy0720 能告诉我么
insert #T select 11
insert #T select 22
insert #T select 33
insert #T select 44delete #T where id>2
select * from #T
/*
ID F
----------- -----------
1 11
2 22
*/select maxid=ident_current('#T') --> 4drop table #T
insert t select 1
insert t select 1
insert t select 1
insert t select 1
go
delete t where ID>2
go
select * from t
go
检查标识信息: 当前标识值 '4',当前列值 '4'。
DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。--drop table t
insert t select 1
insert t select 1
insert t select 1
insert t select 1
go
delete t where ID>2
go
select * from tdrop table tDBCC CHECKIDENT ('t')---这个检查就行了