How to populate a database column with random numbers

前端 未结 2 726
日久生厌
日久生厌 2021-01-16 01:51

How do I populate a int column, currently empty, with random numbers with no duplicates?

2条回答
  •  深忆病人
    2021-01-16 02:37

    If this is an existing table to which you added a new INT column, you can do something like this:

    UPDATE MyTable
    SET MyIntColumn = CONVERT(int, RAND(CHECKSUM(NEWID())) * 10000);
    

    This will populate the empty column with random numbers between 1 and 10000.

提交回复
热议问题