Although it is a bit confusing, but in actual development, it is true that such requirements will be met, but the requirements are not very strict. In that case, it is a good choice to use this method.
Haha the following content is reprinted from CSDB Forum
BlogArticle Http://blog.csdn.net/jinjazz/archive/2009/04/16/4084142.aspx
-
-
SQL code
-
SetNocountOn -- 75151448 rows of data Select Count(*)FromSyscolumns A, syscolumns B, syscolumns C Set Statistics Time On Select Top10 *From( SelectA. NameAsName,Left(B. Name, 10)AsName1, checksum (newid ())AsHash
FromSyscolumns A, syscolumns B, syscolumns C) T WhereHash % 100 = 0 Set Statistics Time Off SetNocountOff
SQL Server execution time: CPU time = 16 ms, occupied time = 4 ms. So BT? However, if you look at it carefully, it is a pseudo-random, and most of the data in the future will not be displayed for a lifetime. However, this is an idea. In the where hash % 100 = 0 clause, 100 is a key factor. to be truly random, at least hash % 700000 is required. It takes 20 seconds for the same machine, but I think it is quite good. If it is hash % 70000, It is 2 seconds. It can be seen that this is basically a linear relationship. This idea should be more practical than order by newid. I gave up the top 10 of order by newid () after 2 minutes and a half of execution. |