Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wanted to insert 1 to 10,000 numbers in sql. i've run the following and it exectuted correctly as well.

SQL
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?
Posted

statement,
SQL
PRINT CONVERT(varchar(20),datediff(ms,@RunDate,GETDATE())/1000.0)+' seconds'

is for describe time taken by while loop to insert 10000 rows in table.
Happy Coding!
:)
 
Share this answer
 
Comments
ARUN K P 26-Aug-13 2:31am    
But tats not required right?
Aarti Meswania 26-Aug-13 2:47am    
yes it's just for information.
ARUN K P 26-Aug-13 2:54am    
ok fine
jaideepsinh 26-Aug-13 9:36am    
5+ve
Aarti Meswania 26-Aug-13 12:24pm    
thank u!
:)
It is used for performance measurement of the insertion means how much time in seconds the insertion procedure have taken
 
Share this answer
 
Comments
ARUN K P 26-Aug-13 2:31am    
ok fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900