2

I want to distribute 116 records to users via SQL but what is the best way to do this randomly, so for example if its worked out that everyone gets 5 rows how do i randomly insert records with a datetime stamp which is different every hour?

So for user 1, i insert every 10 mins, but for user to i want something different, maybe every 5 mins?

I was thinking if i randomly get a number between 5-10 and then use that as my interval? Then populate a temporary table called, [USED] and then do a NOT EXISTS query and make sure my random interval isnt in there.

The idea is to make it appear as though everyone has created there records, so i dont want it to look like a batch insert. It needs to look like a human has done this.

PriceCheaperton
  • 5,071
  • 17
  • 52
  • 94

1 Answers1

1

That does not sound very "random" as it would look fake to have 5 records on each user. This is a better approach I think:

    INSERT INTO your_table (User_ID,Date_Col) 
VALUES ((SELECT TOP 1 ID FROM your_user_table ORDER BY NEWID()),
DATEADD(second, rand()*36000, DATEADD(day, rand()*120, getdate()))
Kuzgun
  • 4,649
  • 4
  • 34
  • 48
  • A good start but i think its more complicated than this. Eg, how do i know how many rows go onto each user? – PriceCheaperton Dec 25 '13 at 14:35
  • If you want it to be really random, you can't. If you distribute rows evenly to users, that won't be so randomized? But if you want to do that, you will need to use a loop. You can see an example here: http://stackoverflow.com/questions/5856073/for-each-in-ms-sql-server (Bishop's answer for 2008) – Kuzgun Dec 26 '13 at 15:47