关于插入递增字段

tryto10000 2008-07-23 11:07:42
欲将表A(bh,mc)数值插入表B(xh,bh,mc)中,怎样实现xh的递增?
...全文
46 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2008-07-23
  • 打赏
  • 举报
回复
[Quote=引用楼主 tryto10000 的帖子:]
欲将表A(bh,mc)数值插入表B(xh,bh,mc)中,怎样实现xh的递增?
[/Quote]

--1
select * , xh = identity(int,1,1) into tmp from A
insert into B select xh , bh , mc from A

--2(假设bh能区分大小,就是说能排序)

insert into b select xh = (select count(1) from A where bh < t.bh) + 1 , * from A t
hery2002 2008-07-23
  • 打赏
  • 举报
回复
1,自增长列,
2,临时表,
3.2005使用row_number()

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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