SQL SERVER ÈçºÎ¶ÁÈ¡Ò³ÃæÉϵÄÊý¾Ý
CSDNÉÏÓÐƪÌû×Óhttp://topic.csdn.net/u/20100223/15/644e6212-9fdc-42de-81ad-785d28ed71d3.html
ÌÖÂÛ²éѯ¼Æ»®¶ÁÈ¡Ë÷ÒýÒ³µÄÎÊÌâ¡£
Ö÷ÒªÎÊÌâÊÇ£º ÔÚÒ»ÕŽ¨Óоۼ¯Ë÷Òý£¨Ã»ÓÐÆäËü·Ç¾Û¼¯Ë÷Òý£©µÄ±íÖ´ÐÐselect count(*) ¡£²éѯÏÔʾɨÃèÁËËùÓеÄË÷ÒýÖмä²ãÒ¶¡£´ÓÀíÂÛÉϽ²£¬ÓÉÓÚÿ¸öÊý¾ÝÒ³¶¼¼Ç¼×ÅËüµÄÉÏÒ»¸öpageºÍÏÂÒ»¸öpage,ÄÇô×îСµÄio¶ÁÈ¡Ó¦¸ÃÊÇ:
¶Á¸ùÒ³--->¶Á×îСµÄÖмäÒ³--->¶ÁÊý¾ÝÒ¶×Ó---->ÒÀ´ÎÍùºó¶ÁÈ«²¿Êý¾ÝÒ³.
µ«Êµ¼ÊÉÏÈ´ÊǶÁÈ¡È«²¿µÄË÷ÒýÖмäÒ³¡£
Ìû×ÓÖбȽϾ«²ÊµÄ»Ø¸´£º
Ê×ÏÈÂ¥Ö÷µÄ˵·¨²»¹»×¼È·£¬¸ù¾ÝÎҵIJâÊÔ½á¹ûÀ´¿´£¬¸ü׼ȷµÄ˵·¨Ó¦¸ÃÊÇsql serverÔÚ×öË÷Òýȫɨ(index full scan)ʱ£¬»áÏÈɨÃèÈ«²¿µÄlevel 1µÄ½Úµã£¬È»ºóÔÚɨÃè´¦ÓÚlevel 0µÄÒ¶½Úµã¡£Ò²¾ÍÊÇ˵һ´ÎË÷ÒýȫɨµÄ˳ÐòÊÇ£¨Õâ¸ö˳Ðò¶ÔÓÚclustered indexºÍÆÕͨindex¶¼ÊÇÒ»ÑùµÄ£©£º
¶Á¸ùÒ³--->¶Á×îСµÄÖмäÒ³£¨level 1ÒÔÉϵIJ㣩--->ÒÀ´Î¶Álevel 1µÄËùÓнڵãµÄË÷ÒýÒ³---->¶ÁÈ«²¿Êý¾ÝÒ³
ÉÏÊö˳Ðò¿ÉÒÔÔÚ½«Êý¾Ý±íË÷Òý²ãÊýÔö¼Óµ½3²ãÒÔÉÏʱµÃµ½ÑéÖ¤¡£
ʵ¼ÊÉÏÎÒ¾õµÃsql serverÕâÑù×öÊǺÜÓеÀÀíµÄ£¬Â¥Ö÷ÈÏΪµÄÊÇËù¶ÁµÄÒ³Ô½ÉÙ£¬io¾ÍԽС£¬ÕâÊDz»¶ÔµÄ¡£¶ÔÓÚsql serverÀ´Ëµ£¬Ò»´Îio²¢²»Ò»¶¨Ö»¶ÁÈ¡Ò»¸öÒ³£¬ºÜ¶àʱºòÌرðÊÇ×ö±íȫɨ»òË÷Òýȫɨʱ£¬sql server¶¼»á¾¡Á¿µÄÈÃÒ»´Îio¶ÁÈ¡¾¡¿ÉÄܶàµÄÊý¾ÝÒ³£¬ÕâÑù²ÅÄܽÏÉÙioµÄ´ÎÊý¡£Îª´ïµ½Õâ¸öÄ¿µÄ£¬sql serverÊ×ÏȾÍÒªÖªµÀËüµ½µ×ÐèÒª¶ÁÈ¡ÄÇЩҳ£¬ÖªµÀÒª¶ÁÈ¡Ò³µÄ·Ö²¼Ö®ºó£¬¾Í¿ÉÒÔ°²ÅÅioµ÷¶ÈÆ÷¾¡¿ÉÄܵĽ«ÁÙ½üµÄÊý¾ÝÒ³ÓÃÒ»´Îio¶ÁÈ¡ÉÏÀ´£¬¶øÒªÖªµÀÐèÒª¶ÁÈ¡Êý¾ÝÒ³µÄ·Ö²¼¾ÍÐèÒªÏȶÁÈ¡µ½level 1ÉϵÄËùÓÐÒ³£¬ÒÔÕÒ³öÒª¶ÁÈ¡ioÒ³µÄ·Ö²¼Çé¿ö£¬È»ºóÔÙ×ö×îÓŵÄio¶ÁÈ¡°²ÅÅ¡£
ͬÑùµÄµÀÀí£¬Èç¹ûsql serverÊÇÏȶ¨Î»µ½Ò¶½ÚµãµÄÆðʼÊý¾ÝÒ³£¬È»ºó´ÓÒÀ´ÎµÄ¶ÁÈ¡ËùÓеÄÊý¾ÝÒ³µÄ»°£¬ÄÇsql server¾ÍÖ»ÄÜÒ»´Îio¶ÁÈ¡Ò»¸öÊý¾ÝÒ³£¬È»ºóÕÒ³ö¶ÔÓ¦µÄÏÂÒ»Ò³µÄÖ¸Õ룬ÔÙÈ¥¶ÁÈ¡ÏÂÒ»¸öÊý¾ÝÒ³£¬ÕâÑùʵ¼ÊÉÏ»¨·ÑµÄio»áÔ¶±ÈÅúÁ¿¶ÁÈ¡Êý¾ÝÒ³¶àºÜ¶àµÄ¡£Õâ¾ÍºÃ±ÈÎÒÃÇÔÚ×ö±íµÄlookupʱ£¬Èç¹ûÐèÒªlookupµÄÐзdz£Ö®¶àµÄ»°sql server»áת¶øÑ¡Ôñ±íɨÃèÀ´´ïµ½Ä¿µÄµÄ¡£
Ô¤¶Á
ÎÒ¾õµÃSQL ServerÄÚ²¿´æÔÚÕâÑùÒ»¸ö»úÖÆ:
Ëü»á¾¡Á¿½«µ±Ç°Ê¹Óõļ°Ê¹ÓÃ×îƵ·±µÄ±íµÄÊý¾Ý¶¼´øµ½bufferÖÐÀ´£¬Õâ¸úbufferµÄËã·¨ÓÐÒ»¶¨µÄ¹Øϵ¡£
ÇåµôbufferáᣬÄã²»×öÈκζ¯×÷£¬¸ô¼¸ÃëÖÓ£¬sql»á×Ô¶¯½«master¿âÖÐһЩ±È½ÏÖØÒªµÄ±í¶¼´øµ½bufferÖУ¬»òÕß
Äãselect * from tb where 1 <>1 £¬¾¡¹
Ïà¹ØÎĵµ£º
in ºÍ existsÆäʵͦºÃÇø±ðµÄ.ÇÒ¿´Ï±߻ù±¾¸ÅÄî¡£
in ÊÇÒ»¸ö¼¯ºÏÔËËã·û.
a in {a,c,d,s,d....}
Õâ¸öÔËËãÖÐ,Ç°ÃæÊÇÒ»¸öÔªËØ,ºóÃæÊÇÒ»¸ö¼¯ºÏ,¼¯ºÏÖеÄÔªËØÀàÐÍÊǺÍÇ°ÃæµÄÔªËØÒ»ÑùµÄ¡£ÊµÏֵĶԼ¯ºÏÖеÄÔªËؽøÐбéÀú£¬ÒÔÈ·¶¨¸ø¶¨µÄÔªËØaÊÇ·ñÓë×Ó²éѯ»òÁбíÖеÄÖµÏàÆ¥Åä¡£
in ÔËËãÓÃÔÚsqlÓï¾äÖÐ,ËüºóÃæ´øµÄselect Ò»¶¨ÊÇÑ¡Ò»¸ ......
--oracleÓÅ»¯slqÓï¾ä
£¨1£©Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
¡¡¡¡OracleµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äú±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£¼ÙÈçÓÐ3¸öÒÔÉ쵀 ......
sql2000º¯Êý´óÈ«1 µ±Ç°ÏµÍ³ÈÕÆÚ¡¢Ê±¼ä
select getdate()
2. dateadd ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ
ÀýÈ磺ÏòÈÕÆÚ¼ÓÉÏ2Ìì
select dateadd(day,2,'2004-10-15') --·µ»Ø£º2004-10-17 00:00:00.000
3. datediff ·µ»Ø¿çÁ½¸öÖ¸¶¨ÈÕÆÚµÄÈ ......
±¸·Ý£º
A. ±¸·ÝÕû¸ö MyNwind Êý¾Ý¿â
˵Ã÷ MyNwind Êý¾Ý¿â½öÓÃÓÚÑÝʾ¡£
ÏÂÀý´´½¨ÓÃÓÚ´æ·Å MyNwind Êý¾Ý¿âÍêÕû±¸·ÝµÄÂß¼±¸·ÝÉ豸¡£
......
ÔÚSQL Server 2005Êý¾Ý¿âÖÐʵÏÖ×Ô¶¯±¸·ÝµÄ¾ßÌå²½Öè:
1¡¢´ò¿ªSQL Server Management Studio
2¡¢Æô¶¯SQL Server´úÀí
3¡¢µã»÷×÷Òµ->н¨×÷Òµ
4¡¢"³£¹æ"ÖÐÊäÈë×÷ÒµµÄÃû³Æ
5¡¢Ð½¨²½Ö裬ÀàÐÍÑ¡T-SQL£¬ÔÚÏÂÃæµÄÃüÁîÖÐÊäÈëÏÂÃæÓï¾ä£¨ºìÉ«²¿·ÖÒª¸ù¾Ý×Ô¼º ......