插入一条新数据,如何返回主键值id,id是自动增长的,请帮忙! 插入一条新数据,如何返回主键值id,id是自动增长的,请帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 create table Temp(id int identity(1,1),col int)goinsert into temp select 5insert into temp select 8insert into temp select 100go--在执行插入后立即调用select @@IDENTITY/*---------------------------------------3(1 行受影响)*/godrop table temp @@IDENTITY、SCOPE_IDENTITY 和 IDENT_CURRENT 可以去查查 都差不多 insert ........select @@IDENTITY insert into....;select @@identity select ident_current('tb') ---返回表tb最后一个插入的identity列的值 select @@IDENTITY ----返回最新插入的identity值 select SCOPE_IDENTITY() ----返回最新插入的identity值 --@@identity 和 scope_identity()的区别是 @@identity 的作用域是全部的回话,不只是当前表,会返回所有域中 --刚插入的identity值,scope_identity() 只返回当前回话中新插入的identity值 select IDENT_INCR('tb') ---返回表tb identity列的原始增量值 select IDENT_SEED('tb') ---返回表tb identity列的原始种子值,即起始值 有关sysobject提问: sql语句中 分组 求和的问题 存储过程执行出错 局域网总是访问不了sql数据库,帮忙! 急求一sql语句! 请教修改SQL时间?! 求sql语句一条(请教) update iteminf set (select image1 from iteminf)=(select image1 from iteminf2 where model_no=iteminf.model_no) 高分求助(不唯一的字段改成唯一) 请大家来讨论各种JOIN的用法!(15天结贴) SQL SERVER 2008 角色一大堆,但只有一个可以用 一个优化查询的问题
go
insert into temp select 5
insert into temp select 8
insert into temp select 100
go
--在执行插入后立即调用
select @@IDENTITY
/*
---------------------------------------
3(1 行受影响)*/
go
drop table temp
select @@IDENTITY
select ident_current('tb') ---返回表tb最后一个插入的identity列的值
select @@IDENTITY ----返回最新插入的identity值
select SCOPE_IDENTITY() ----返回最新插入的identity值
--@@identity 和 scope_identity()的区别是 @@identity 的作用域是全部的回话,不只是当前表,会返回所有域中
--刚插入的identity值,scope_identity() 只返回当前回话中新插入的identity值
select IDENT_INCR('tb') ---返回表tb identity列的原始增量值
select IDENT_SEED('tb') ---返回表tb identity列的原始种子值,即起始值