Populate dummy records in SQL Server

Story by Abhilash on SQL Server


Last day, I was playing with paging in SQL Server and had to create some test data to test the same. Here goes the script to generate test data.

DECLARE @UserTable TABLE (Id int, Name nvarchar(150))
;WITH cte AS
    SELECT 1 Id
    UNION all
    SELECT Id + 1
    FROM cte WHERE   Id + 1 <= 100000
INSERT INTO @UserTable(Id,Name)
    SELECT Id, Concat('Name_', convert(int, convert (varbinary(4), NEWID(), 1))) AS Name FROM cte c 
SELECT u.Id, u.Name
    Into DemoUser
    FROM    @UserTable u


Hope this helps.

comments powered by Disqus

Related Story   →

Paging re-imagined in SQL Server

How easy can you implement paging in SQL Server? Here is how you can achieve it.