Posted by: R Manimaran | July 4, 2008

Inserting Random Values into SQL SERVER Table

Inserting Random numbers into a Table Column

We may have a situation to insert some random numbers into our table. For that purpose we can use the Rand() Function which is available in SQL SERVER.

Example:

Set noCount on

— Declare a Table

Declare @Table1 Table(id int,Rndvalue int)

Declare @index int

select @index=1

– insert 10 Random values into the Table

while @index<11

Begin

–Generate Random Values

Insert into @Table1 values(@index,ceiling(1000*Rand()))

–Increment the id value

Select @index=@index+1

end

—-Select the values

Select id,RndValue from @Table1

—–Output

Random Values insertion

Random Values insertion


Leave a response

Your response:

Categories