SQLÂß¼²éѯ´¦Àí˳Ðò
SQL²»Í¬ÓÚÆäËû±à³ÌÓïÑÔµÄ×îÃ÷ÏÔÌØÕ÷ÊÇ´¦Àí´úÂëµÄ˳Ðò¡£ÔÚ´ó¶àÊý¾Ý¿âÓïÑÔÖУ¬´úÂë°´±àÂë˳Ðò±»´¦Àí¡£µ«ÔÚSQLÓï¾äÖУ¬µÚÒ»¸ö±»´¦ÀíµÄ×Ó¾äʽfrom£¬¶ø²»ÊǵÚÒ»³öÏÖµÄSELECT¡£SQL²éѯ´¦ÀíµÄ²½ÖèÐòºÅ£º
view source
< id="highlighter_299531_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash">
print?
1
(8) SELECT (9) DISTINCT (11) <TOP_specification> <select_list>
2
(1) from <left_table>
3
(3) <join_type> JOIN <right_table>
4
(2) ON <join_condition>
5
(4) WHERE <where_condition>
6
(5) GROUP BY <group_by_list>
7
(6) WITH {CUBE | ROLLUP}
8
(7) HAVING <having_condition>
9
(10) ORDER BY <order_by_list>
ÒÔÉÏÿ¸ö²½Ö趼»á²úÉúÒ»¸öÐéÄâ±í£¬¸ÃÐéÄâ±í±»ÓÃ×÷ÏÂÒ»¸ö²½ÖèµÄÊäÈë¡£ÕâЩÐéÄâ±í¶Ôµ÷ÓÃÕߣ¨¿Í»§¶ËÓ¦ÓóÌÐò»òÕßÍⲿ²éѯ£©²»¿ÉÓá£Ö»ÓÐ×îºóÒ»²½Éú³ÉµÄ±í²Å»á»á¸øµ÷ÓÃÕß¡£Èç¹ûûÓÐÔÚ²éѯÖÐÖ¸¶¨Ä³Ò»¸ö×Ӿ䣬½«Ìø¹ýÏàÓ¦µÄ²½Öè¡£
Âß¼²éѯ´¦Àí½×¶Î¼ò½é£º
1¡¢ from£º¶Ôfrom×Ó¾äÖеÄÇ°Á½¸ö±íÖ´Ðеѿ¨¶û»ý£¨½»²æÁª½Ó£©£¬Éú³ÉÐéÄâ±íVT1¡£
2¡¢ ON£º¶ÔVT1Ó¦ÓÃONɸѡÆ÷£¬Ö»ÓÐÄÇЩʹ<join_condition>ΪÕæ²Å±»²åÈëµ½TV2¡£
3¡¢ OUTER (JOIN):Èç¹ûÖ¸¶¨ÁËOUTER JOIN£¨Ïà¶ÔÓÚCROSS JOIN»òINNER JOIN£©£¬±£Áô±íÖÐδÕÒµ½Æ¥ÅäµÄÐн«×÷ΪÍⲿÐÐÌí¼Óµ½VT2£¬Éú³ÉTV3¡£Èç¹ûfrom×Ó¾ä°üº¬Á½¸öÒÔÉÏµÄ±í£¬Ôò¶ÔÉÏÒ»¸öÁª½ÓÉú³ÉµÄ½á¹û±íºÍÏÂÒ»¸ö±íÖظ´Ö´Ðв½Öè1µ½²½Öè3£¬Ö±µ½´¦ÀíÍêËùÓеıíλÖá£
4¡¢ WHERE£º¶ÔTV3Ó¦ÓÃWHEREɸѡÆ÷£¬Ö»ÓÐʹ<where_condition>ΪtrueµÄÐвŲåÈëTV4¡£
5¡¢ GROUP BY£º°´GROUP BY×Ó¾äÖеÄÁÐÁбí¶ÔTV4ÖеÄÐнøÐзÖ×飬Éú³ÉTV5¡£
6¡¢ CUTE|ROLLUP£º°Ñ³¬×é²åÈëVT5£¬Éú³ÉVT6¡£
7¡¢ HAVING£º¶ÔVT6Ó¦ÓÃHAVINGɸ
Ïà¹ØÎĵµ£º
»ù±¾µÄSql±àдעÒâÊÂÏî
¾¡Á¿ÉÙÓÃIN²Ù×÷·û£¬»ù±¾ÉÏËùÓеÄIN²Ù×÷·û¶¼¿ÉÒÔÓÃEXISTS´úÌæ¡£
²»ÓÃNOT IN²Ù×÷·û£¬¿ÉÒÔÓÃNOT EXISTS»òÕßÍâÁ¬½Ó+Ìæ´ú¡£
OracleÔÚÖ´ÐÐIN×Ó²éѯʱ£¬Ê×ÏÈÖ´ÐÐ×Ó²éѯ£¬½«²éѯ½á¹û·ÅÈëÁÙʱ±íÔÙÖ´ÐÐÖ÷²éѯ¡£¶øEXISTÔòÊÇÊ×Ïȼì²éÖ÷²éѯ£¬È»ºóÔËÐÐ×Ó²éѯֱµ½ÕÒµ½
µÚÒ»¸öÆ¥ÅäÏî¡£NOT EXISTS±ÈNOT INЧÂÊÉ ......
tempdb¶ÔSQL ServerÊý¾Ý¿âÐÔÄÜÓкÎÓ°Ïì
±¾ÎĹؼü´Ê£ºSQL Server ÍøÂç
Ïà·´Èç¹û·ÃÎʺÜƵ·±,loading¾Í»á¼ÓÖØ,tempdbµÄÐÔÄܾͻá¶ÔÕû¸öDB²úÉúÖØÒªµÄÓ°Ïì.ÓÅ»¯tempdbµÄÐÔÄܱäµÄºÜÖØÒªµÄ,ÓÈÆä¶ÔÓÚ´óÐÍÊý¾Ý¿â.Èç¹ûʹÓÃÁÙʱ±í´¢´æ´óÁ¿µÄÊý¾ÝÇÒƵ·±·ÃÎÊ,¿¼ÂÇÌí¼ÓindexÒÔÔö¼Ó²éѯЧÂÊ.
¡¡ 1.SQL ServerϵͳÊý¾Ý¿â½é ......
tempdb¶ÔSQL ServerÊý¾Ý¿âÐÔÄÜÓкÎÓ°Ïì
±¾ÎĹؼü´Ê£ºSQL Server ÍøÂç
Ïà·´Èç¹û·ÃÎʺÜƵ·±,loading¾Í»á¼ÓÖØ,tempdbµÄÐÔÄܾͻá¶ÔÕû¸öDB²úÉúÖØÒªµÄÓ°Ïì.ÓÅ»¯tempdbµÄÐÔÄܱäµÄºÜÖØÒªµÄ,ÓÈÆä¶ÔÓÚ´óÐÍÊý¾Ý¿â.Èç¹ûʹÓÃÁÙʱ±í´¢´æ´óÁ¿µÄÊý¾ÝÇÒƵ·±·ÃÎÊ,¿¼ÂÇÌí¼ÓindexÒÔÔö¼Ó²éѯЧÂÊ.
¡¡ 1.SQL ServerϵͳÊý¾Ý¿â½é ......
¼Æ»®ÓÚ2008ÄêµÚÒ»¼¾¶È·¢²¼µÄSQL Server 2008²»½ö¶ÔÔÓÐÐÔÄܽøÐÐÁ˸Ľø£¬»¹Ìí¼ÓÁËÐí¶àÐÂÌØÐÔ£¬±ÈÈçÐÂÌíÁËÊý¾Ý¼¯³É¹¦ÄÜ£¬¸Ä½øÁË·ÖÎö·þÎñ£¬±¨¸æ·þÎñ£¬ÒÔ¼°Office¼¯³ÉµÈµÈ¡£
¡¡¡¡SQL Server¼¯³É·þÎñ
¡¡¡¡SSIS(SQL Server¼¯³É·þÎñ)ÊÇÒ»¸öǶÈëʽӦÓóÌÐò£¬ÓÃÓÚ¿ª·¢ºÍÖ´ÐÐETL(½âѹËõ¡¢×ª»»ºÍ¼ÓÔØ)°ü¡£SSIS´úÌæÁËSQL 2000µÄDTS¡£Õ ......
SQL Server2008ÐÐÊý¾ÝºÍÒ³Êý¾ÝѹËõ½âÃÜ
Êý¾ÝѹËõÒâζ׿õСÊý¾ÝµÄÓдÅÅÌÕ¼ÓÃÁ¿£¬ËùÒÔÊý¾ÝѹËõ¿ÉÒÔÓÃÔÚ±í£¬¾Û¼¯Ë÷Òý£¬·Ç¾Û¼¯Ë÷Òý£¬ÊÓͼË÷Òý»òÊÇ·ÖÇø±í£¬·ÖÇøË÷ÒýÉÏ¡£2.Ç°±êѹËõ£ºÃ¿Ò»Ò³ÖеÄËùÓÐÁУ¬ÔÚÐбêÍ·ÏÂÃ棬ÿÐж¼´æ´¢×ÅÒ»¸öÐж¨ÒåÖµ£¬Ñ¹Ëõºó£¬ËùÓÐÐеĶ¨ÒåÖµ¶¼±»Ìæ»»³ÉÐÐÍ·ÖµµÄÒýÓá£
¡¡¡¡±¾ÎĽ«Îª´ó¼Ò½éÉÜ ......