插入从1到1300的数字的问题

lutter 2003-12-25 10:37:19
表中有一字段为INT,现在想将从1到1300的数字倒入到这个字段中!请问各位高手怎么才能最快的实现!我可不想一个一个的输入那样效率太低!我是新手,望赐教
...全文
64 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-12-25
  • 打赏
  • 举报
回复
同意楼上.
j9988 2003-12-25
  • 打赏
  • 举报
回复
select top 1300 identity(int,1,1) as id into #t from sysobjects A,sysobjects B
insert tab(intfield) select id from #t order by id
drop table #t
大力 2003-12-25
  • 打赏
  • 举报
回复
用 while 变量<1300
begin
insert into ....
end
jingxijun 2003-12-25
  • 打赏
  • 举报
回复
注明:上面的例子是仿造J老师的。
jingxijun 2003-12-25
  • 打赏
  • 举报
回复
可以直接把如下语句在查询分析器执行看看:

create table test(ord int,name nvarchar(8))
select top 1300 identity(int,1,1) as id into #t from sysobjects A,sysobjects B
insert test(ord) select id from #t order by id
drop table #t
select * from test


另请教J老师,若楼主的意思是:
原表中已有N条记录,然后需从头开始将某字段的值改为1-1300呢
victorycyz 2003-12-25
  • 打赏
  • 举报
回复
我来解释一下:

--这句照原样:
select top 1300 identity(int,1,1) as id into #t from sysobjects A,sysobjects B

--这句中的tab改成你的表的名字,intfield改成你要添加1-1300的数字的字段。
insert tab (intfield) select id from #t order by id

--这句照原样:
drop table #t

执行后,打开你的表看看。
lutter 2003-12-25
  • 打赏
  • 举报
回复
我运行了,可是这1300条记录存到哪里了呢?这些SQL语句代表什么?对不起,小弟才疏学浅,愿各位高手赐教
gmlxf 2003-12-25
  • 打赏
  • 举报
回复
是的,查询分析器里面直接执行就行了。
wzh1215 2003-12-25
  • 打赏
  • 举报
回复
我不是很明白2楼的意思!是在查询分析器中直接输入那些命令吗?
---
可以
lutter 2003-12-25
  • 打赏
  • 举报
回复
我不是很明白2楼的意思!是在查询分析器中直接输入那些命令吗?

34,576

社区成员

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

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