SQL中 如果我要建一张表,表中的数据是1到10000,有什么快捷方法写入,可以用循环吗?那样的循

SQL中 如果我要建一张表,表中的数据是1到10000,有什么快捷方法写入,可以用循环吗?那样的循环怎么写?

第1个回答  2014-04-05
---如果数据库中已经存在test表则,将其drop掉,
if exists (select * from dbo.Sysobjects where id='test' and OBJECTPROPERTY(OBJECT_ID('test'),'IsTable')=1 )
drop table test
--新建数据库
create table test
(
id int
)

declare @i int,@num int --定义变量用来存储循环初始值和结束值
select @i=1,@num=1000

while (@i<=@num) ---进入循环
begin
insert into test values(@i)
select @i+=1
end

select * from test

drop table test --删除实体表,如果程序真用则就不要删除了本回答被提问者采纳
第2个回答  2014-04-05
自己写个简单的代码就搞定啊 这个很容易的,当然要循环。
第3个回答  2014-04-05
先创建一个表
create table t
(id numeric)

运行下面语句插入数据
declare @i int
begin
set @i=1

while (@i <=10000)
begin
insert into t(id)
values (@i)
set @i=@i+1
end
end追问

我选了另一个人的,不好意思,你的选不了了

第4个回答  2014-04-05
用EXCEL写了导入多简单啊