您的位置:首页 > 博客中心 > 数据库 >

SQL SERVER SCOPE_IDENTITY函数的应用

时间:2022-03-10 18:19

--====================================
--SCOPE_IDENTITY()函数使用: 只返回插入到当前作用域中的值
--返回在当前会话中的任何表内所生成的最后一个标识值
--另外两个函数 floor ,Ceiling
--select floor(12.99) select Ceiling(12.01)
--====================================
if object_id(‘tempdb..#BatchPool‘) is  null
begin 
    create table #BatchPool
    (
        BatchID bigint identity,
        Value int
    )
end
declare @BatchID bigint 
insert into #BatchPool(Value) 
select floor(rand()*1000) 

select *
from #BatchPool

select @BatchID =  SCOPE_IDENTITY();

select @BatchID

--drop table #BatchPool

 

SQL SERVER SCOPE_IDENTITY函数的应用,布布扣,bubuko.com

热门排行

今日推荐

热门手游