Here is a little script to create a table filled with random numbers. Sometimes this is usefull when you are testing functions, views or other things.
/* Check if allready created, then delete */
USE [>>your-database-name<<]
GO
SET NOCOUNT ON;
IF OBJECT_ID('dbo.Nums', 'U') IS NOT NULL DROP TABLE dbo.Nums;
/* Create test table.
This example is with two colomns, IdNumber and RandomNumber,
change this for your own need */
CREATE TABLE dbo.Nums(
IdNumber INT NOT NULL PRIMARY KEY,
RandomNumber INT NOT NULL);
DECLARE @max AS INT, @rc AS INT;
SET @max = 100000; /* Change this to as many rows you want */
SET @rc = 1;
/* Fill the table, the '1000' is a multiplying factor */
WHILE @rc <= @max
BEGIN
INSERT INTO dbo.Nums
VALUES(@rc, DATEPART(ms,GETDATE())*RAND()*1000);
SET @rc = @rc + 1;
END
/* show the contents */
SELECT [IdNumber],[RandomNumber]
FROM [InsideTSQL2008Test].[dbo].[Nums];
The RAND() function together with the milliseconds from DATEPART() gives the RandomNumber. Because the milliseconds are repeating themselves the result is not 100% random, there might be two equal values and there are some cyclic values each 1000 milliseconds.