一次性插入大量数据,只能使用循环,
如:游标,while 循环语句
下面介绍While 循环插入数据,
SQL 代码如下:
IF OBJECT_ID('dbo.Nums') IS NOT NULL
DROP TABLE dbo.Nums;
GO
CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY);
DECLARE @max AS INT, @rc AS INT;
SET @max = 5000000;
SET @rc = 1;
INSERT INTO Nums VALUES(1);
WHILE @rc * 2 <= @max
BEGIN
INSERT INTO dbo.Nums SELECT n + @rc FROM dbo.Nums;
SET @rc = @rc * 2;
END
INSERT INTO dbo.Nums SELECT n + @rc FROM dbo.Nums WHERE n + @rc <= @max;
--以上函数取自Inside SQL Server 2005: T-SQL Query一书。
INSERT dbo.Sample SELECT n, RAND(CAST(NEWID() AS BINARY(16))) FROM Nums
要不你用游标吧,或者用循环
CREATE proc [dbo].[存储过程名字]
as
Declare @参数 int
declare cursor1 cursor for
select m_n数据列 from 数据表
open cursor1
fetch next from cursor1 into @参数
while @@fetch_status =0
begin
插入语句
fetch next from cursor1 into @参数
end
close cursor1
Deallocate cursor1
这个是用游标写的存储过程,看一下对你有帮助吗
declare @datese dateTime
set @datese='2012-06-04 00:00:000'
while @datese<'2012-06-18 23:59:59:000'
begin
set @datese=DATEADD(S,3,@datese)
insert into 你的表名 values([NODEaddr]的值,@datese,[Flag_comm],……,[expand20]的值
)
end
就这样,直接把表名一改执行
用任务调度命令crontab试下吧,详细写法你可以百度下