这样的sql语句怎么写?帮帮忙

不懂就要问 2011-04-23 11:17:34
数据库某表主键自增,是很常见的情形。在ASP. Net或C#程序中,要求向该表插入一条记录,并马上从该表查出这条记录。不能使用时间戳,请问你如何实现?
...全文
67 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
叶子 2011-04-23
  • 打赏
  • 举报
回复

declare @t table(id int identity ,col varchar(20))
--插入一条数据
insert into @t
select cast(rand() as varchar(20))
--得到刚插入的数据
select * from @t where id=@@identity
快溜 2011-04-23
  • 打赏
  • 举报
回复
insert into tb 
select ...

select top 1 * from tb order by 主键 desc
水族杰纶 2011-04-23
  • 打赏
  • 举报
回复
if object_id('tb')is not null drop table tb
go
create table tb(Id int identity,name nvarchar(10))
insert tb output inserted.ID select '张三'
/*
ID
-----------
1

*/
Codematic无语呀 2011-04-23
  • 打赏
  • 举报
回复
用参数传递 output 嘿嘿 应该可以吧!!
你参考下分页存储过程的 传出总记录参数 肯定行的
Shawn 2011-04-23
  • 打赏
  • 举报
回复
create TABLE test(id int IDENTITY PRIMARY KEY ,col varchar(20))
--插入一条数据
insert into test
select 'record1'
--得到刚插入的数据
select * from test where id = SCOPE_IDENTITY()

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧