Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Sql NewId() Ëæ»úÊý £¨×ª£©


´ÓA±íËæ»úÈ¡10Ìõ¼Ç¼,ÓÃSELECT TOP 10 * from ywle order by newid()
order by Ò»°ãÊǸù¾Ýijһ×Ö¶ÎÅÅÐò,newid()µÄ·µ»ØÖµ ÊÇuniqueidentifier ,order by newid()Ëæ»úÑ¡È¡¼Ç¼ÊÇÈçºÎ½øÐеÄ
newid()ÔÚɨÃèÿÌõ¼Ç¼µÄʱºò¶¼Éú³ÉÒ»¸öÖµ, ¶øÉú³ÉµÄÖµÊÇËæ»úµÄ, ûÓдóСд˳Ðò. ËùÒÔ×îÖÕ½á¹ûÔÙ°´Õâ¸öÅÅÐò, ÅÅÐòµÄ½á¹ûµ±È»¾ÍÊÇÎÞÐòµÄÁË
»òÕß
select   top   10   *,newid()   as   Random   from   ywle where   ywlename='001'   ordey   by   Random
ÏÂÕßЧÂÊÒª¸ßЩ
ÒòΪnewid()·µ»ØµÄÊÇuniqueidentifierÀàÐ͵ÄΨһֵ¡£newid()ÿ´Î²úÉúµÄÖµ¶¼²»Ò»Ñù£¬ÄÇô¸ù¾ÝÕâÑùµÄÖµ½øÐÐÅÅÐò£¬Ã¿´ÎµÄ½á¹ûÒ²ÊDz»Ò»ÑùµÄ¡£
Ô­ÀíÊÇ °ÑËùÓеÄID³öÈ¡È»ºóÓÃËæ»úº¯ÊýÈ¡³öÆäÖÐÒ»¸ö,È»ºóÓÃÕâ¸öËæ»úÈ¡µ½µÄIDÈ¥Êý¾Ý¿âÀïÔÙÈ¡³ö¼Ç¼£¬ËùÓдú¼ÛÓеã´ó¡£
sql serverµÄËæ»úº¯ÊýnewID()ºÍRAND()
SELECT * from Northwind..Orders ORDER BY NEWID()
--Ëæ»úÅÅÐò
SELECT TOP 10 * from Northwind..Orders ORDER BY NEWID()
--´ÓOrders±íÖÐËæ»úÈ¡³ö10Ìõ¼Ç¼
ʾÀý
A.¶Ô±äÁ¿Ê¹Óà NEWID º¯Êý
ÒÔÏÂʾÀýʹÓà NEWID() ¶ÔÉùÃ÷Ϊ uniqueidentifier Êý¾ÝÀàÐ͵ıäÁ¿¸³Öµ¡£ÔÚ²âÊÔ uniqueidentifier Êý¾ÝÀàÐͱäÁ¿µÄֵ֮ǰ£¬ÏÈÊä³ö¸ÃÖµ¡£
-- Creating a local variable with DECLARESET syntax.
DECLARE @myid uniqueidentifier
SET @myid = NEWID()
PRINT 'Value of @myid is '+ CONVERT(varchar(255), @myid)
ÏÂÃæÊǽá¹û¼¯£º
Value of @myid is 6F9619FF-8B86-D011-B42D-00C04FC964FF
×¢Ò⣺ 
NEWID ¶Ôÿ̨¼ÆËã»ú·µ»ØµÄÖµ¸÷²»Ïàͬ¡£ËùÏÔʾµÄÊý×Ö½öÆð½âÊÍ˵Ã÷µÄ×÷Óá£
Ëæ»úº¯Êý£ºrand()
ÔÚ²éѯ·ÖÎöÆ÷ÖÐÖ´ÐУºselect rand()£¬¿ÉÒÔ¿´µ½½á¹û»áÊÇÀàËÆÓÚÕâÑùµÄËæ»úСÊý£º0.36361513486289558£¬ÏñÕâÑùµÄСÊýÔÚʵ¼ÊÓ¦ÓÃÖÐÓõò»¶à£¬Ò»°ãҪȡËæ»úÊý¶¼»áÈ¡Ëæ»úÕûÊý¡£ÄǾͿ´ÏÂÃæµÄÁ½ÖÖËæ»úÈ¡ÕûÊýµÄ·½·¨£º
1¡¢
A£ºselect  floor(rand()*N)  ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12.0
B£ºselect cast( floor(rand()*N) as int)  ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12
2¡¢
A£ºselect ceiling(rand() * N)  ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12.0
B£ºselect cast(ceiling(rand() * N) as int)  ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12
    ÆäÖÐÀïÃæµÄNÊÇÒ»¸öÄãÖ¸¶¨µÄÕûÊý£¬Èç1


Ïà¹ØÎĵµ£º

´¢´æ¹ý³Ì SQL ¿ìËÙÉÏÊÖ¡£

   Ò»¡¢SQL´æ´¢¹ý³ÌµÄ¸ÅÄÓŵ㼰Óï·¨
¡¡¡¡ÕûÀíÔÚѧϰ³ÌÐò¹ý³Ì֮ǰ£¬ÏÈÁ˽âÏÂʲôÊÇ´æ´¢¹ý³Ì?ΪʲôҪÓô洢¹ý³Ì£¬ËûÓÐÄÇЩÓŵã
¡¡¡¡¶¨Ò壺½«³£ÓõĻòºÜ¸´ÔӵŤ×÷£¬Ô¤ÏÈÓÃSQLÓï¾äдºÃ²¢ÓÃÒ»¸öÖ¸¶¨µÄÃû³Æ´æ´¢ÆðÀ´, ÄÇôÒÔºóÒª½ÐÊý¾Ý¿âÌṩÓëÒѶ¨ÒåºÃµÄ´æ´¢¹ý³ÌµÄ¹¦ÄÜÏàͬµÄ·þÎñʱ,Ö»Ðèµ÷ÓÃexecute,¼´¿É×Ô¶¯Íê³ ......

[Sql]EXCEPT ºÍ INTERSECT¹Ø¼ü×Ö

[Sql]EXCEPT ºÍ INTERSECT¹Ø¼ü×Ö
http://www.cnblogs.com/treeyh/archive/2008/07/01/1232845.html
EXCEPT
´Ó EXCEPT ²Ù×÷Êý×ó±ßµÄ²éѯÖзµ»ØÓұߵIJéѯδ·µ»ØµÄËùÓзÇÖظ´Öµ¡£
INTERSECT
·µ»Ø INTERSECT ²Ù×÷Êý×óÓÒÁ½±ßµÄÁ½¸ö²éѯ¾ù·µ»ØµÄËùÓзÇÖظ´Öµ¡£
A. ʹÓà EXCEPT
ÔÚʾÀýÖÐʹÓà TableA ºÍ TableB ÖеÄÊý¾Ý¡£ ......

Tips on Optimizing SQL Server Clustered Indexes

http://www.sql-server-performance.com/tips/clustered_indexes_p1.aspx
As a rule of thumb, every table should have a clustered index. Generally, but not always, the clustered index should be on a column that monotonically increases--such as an identity column, or some other column where the value is ......

ÈýÖÖSQL·ÖÒ³Óï¾ä

À´×Ô£ºhttp://www.cnblogs.com/morningwang/archive/2009/01/02/1367277.html
ÓйطÖÒ³ SQL µÄ×ÊÁϺܶ࣬ÓеÄʹÓô洢¹ý³Ì£¬ÓеÄʹÓÃÓαꡣ±¾È˲»Ï²»¶Ê¹ÓÃÓα꣬ÎÒ¾õµÃËüºÄ×Ê¡¢Ð§Âʵͣ»Ê¹Óô洢¹ý³ÌÊǸö²»´íµÄÑ¡Ôñ£¬ÒòΪ´æ´¢¹ý³ÌÊǾ­¹ýÔ¤±àÒëµÄ£¬Ö´ÐÐЧÂʸߣ¬Ò²¸üÁé»î¡£ÏÈ¿´¿´µ¥Ìõ SQL Óï¾äµÄ·ÖÒ³ SQL °É¡£
·½·¨1£º
ÊÊÓÃ ......

SQLÉú³ÉËæ»ú×Ö·û´®

declare @str varchar(50)
 declare   @i   int  
 set @str = ''
   set   @i=0  
   while   @i<50 
   begin  
        set   @str = ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ