Search code examples
c#sqlsql-server-2008tool-rec

Fill SQL Server table with test data


Is there a free utility that will fill up your database tables with test data?


Solution

  • Check this:

    --Declare variables
    
    DECLARE @NoOfRows INT, @StartVal INT, @EndVal INT, @Range INT
    
    --Preset the variables
    
     SELECT @NoOfRows = 10000, @StartVal = 10, @EndVal = 20, @Range = @EndVal - @StartVal + 1
    
    --Create the test table with "random values" integers and floats
    
    SELECT TOP (@NoOfRows) 
    SomeRandomInteger =  ABS(CHECKSUM(NEWID())) % @Range + @StartVal, 
    SomeRandomFloat = RAND(CHECKSUM(NEWID())) * @Range + @StartVal
    
    INTO #TempTable
    
    FROM sys.all_columns ac1
    CROSS JOIN sys.all_columns ac2
    
    SELECT * FROM #TempTable