本文介绍了插入1到10,000之间的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在sql中插入1到10,000个数字。我运行了以下内容并且也正确地执行了。
I wanted to insert 1 to 10,000 numbers in sql. i've run the following and it exectuted correctly as well.
DROP TABLE NumbersTest
DECLARE @RunDate datetime
SET @RunDate=GETDATE()
CREATE TABLE NumbersTest (Number INT NOT NULL);
DECLARE @i INT;
SELECT @i = 1;
SET NOCOUNT ON
WHILE @i <= 10000
BEGIN
INSERT INTO dbo.NumbersTest(Number) VALUES (@i);
SELECT @i = @i + 1;
END;
SET NOCOUNT OFF
ALTER TABLE NumbersTest ADD CONSTRAINT PK_NumbersTest PRIMARY KEY CLUSTERED (Number)
PRINT CONVERT(varchar(20),datediff(ms,@RunDate,GETDATE())/1000.0)+' seconds'
SELECT COUNT(*) FROM NumbersTest
select * from NumbersTest
现在我的问题是我知道日期时间部分。谁可以解释一下?
Now my question is i din understood that date time part. can any one explain about that?
推荐答案
PRINT CONVERT(varchar(20),datediff(ms,@RunDate,GETDATE())/1000.0)+' seconds'
用于描述while循环在表中插入10000行所花费的时间。
快乐编码!
:)
is for describe time taken by while loop to insert 10000 rows in table.
Happy Coding!
:)
这篇关于插入1到10,000之间的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!