Skip to content
Advertisement

Update table with using NEWID() function

In general, I would update a table randomly like the following scripts.

However, I get some issue. It would update more/less then 2 rows. I try execute the following scripts many times for debug. The results are not always only two records. If I remove the order by newid(), the number of output result will be fine. It seems like the problem in newid(). How can I solve this problem? Thanks

Advertisement

Answer

You can try this:

However if you filter out the DefaultImageId=1 in inner query, it would be even better too. You should note that in this case, the inner query might produce less than 2 records.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement