sql server 批量添加问题

helloshihaiping 2011-09-23 10:41:27
我建了一个带有序号的表,怎么实现批量添加呢,初学者,要详细地代码案例,谢谢
...全文
85 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
我没有吃饭 2011-09-24
  • 打赏
  • 举报
回复

--同理,如果你想把其它表的资料转移到你创建的这个表中,插入的时候要指定列,避开自增列
insert into tb(aa,bb)
select aa,bb from tbold
我没有吃饭 2011-09-24
  • 打赏
  • 举报
回复

--假设你的序号列是 tid,还有其它两列aa,bb,插入的时候
insert into tb(aa,bb)
select 'a1','b1' union all
select 'a2','b2' union all
select 'a3','b4' union all
select 'a5','b4'
--如果字段属性是int,money等这些,可以不用单引号''
-晴天 2011-09-24
  • 打赏
  • 举报
回复
批量添加可以从客户端直接输入经 union 的一系列数据,比如:
insert into tb select 1,'aa'
unoin all select 2,'bb'
union all select 3,'cc'
union all select 4,'dd'
也可以从其他表中通过查询获得,比如:
insert into tb select * from othertb where yourcn
你想要批量添加什么?
helloshihaiping 2011-09-24
  • 打赏
  • 举报
回复
昨天的问题还木有解决呢 唉 郁闷
helloshihaiping 2011-09-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 rfq 的回复:]
declare @tab table (iid int )
insert into @tab
select row_number() over(order by a.object_id) from sys.objects a,sys.objects b
select * from @tab
[/Quote]
能写详细一点吗,最好给我写上注释,帮帮忙,谢啦
yubofighting 2011-09-23
  • 打赏
  • 举报
回复
insert into tb(字段) values(..)
忠臣 2011-09-23
  • 打赏
  • 举报
回复
复制两一个表的数据插入本表就是了
rfq 2011-09-23
  • 打赏
  • 举报
回复
declare @tab table (iid int )
insert into @tab
select row_number() over(order by a.object_id) from sys.objects a,sys.objects b
select * from @tab

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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