sql unionÓ÷¨ºÍsql union allÓ÷¨,sql unionЧÂÊ
sql unionÓ÷¨ºÍsql union allÓ÷¨,sql unionЧÂÊ
1¡¢sql unionÓ÷¨
sql unionÔÚ²éѯÖпÉÒÔ½«Á½¸öSQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£Èç¹ûÕâÑù¿´µÄ»°£¬ UNION ¸ú JOIN ÊÇÏàËƵģ¬Á½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£
sql unionµÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£
sql unionÖ»Êǽ«Á½¸ö½á¹ûÁª½áÆðÀ´Ò»ÆðÏÔʾ£¬²¢²»ÊÇÁª½áÁ½¸ö±í£¬sqlÓ÷¨ÈçÏ£º
Á½¸ö±í¸ñ£¬ StoreData_200903 ±í¸ñ StoreData_200904£¬ÕâÁ½Õűí¸ñµÄÊý¾Ý½á¹¹ÊÇÍêÈ«Ò»ÑùµÄ£¬Ö»ÊÇ´æ·ÅÁ˲»Í¬Ô·ݵÄÊý¾Ý¿â£¨×¢Ò⣺ÕâÑù×öÊÇΪÁËÄܹ»·Ö±í£¬¶øÇÒ¿ÉÒÔ°´Ô´浵Êý¾Ý£©£¬ÏÖÔÚÐèÒªÁªºÏ²éѯ£¬¾ÍÊÇ´ÓÁ½¸ö±íÖвéѯ³öÊý¾Ý£¬SQL Óï¾ä£º
SELECT top 50 from StoreData_200903
UNION
SELECT top 50 from StoreData_200904
2¡¢sql union allÓ÷¨
sql union allÕâ¸öÖ¸ÁîµÄÄ¿µÄÒ²ÊÇÒª½«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÔÚÒ»Æð¡£ sql union allºÍ sql union²»Í¬Ö®´¦ÔÚÓÚ sql union all»á½«Ã¿Ò»´Î·ûºÏÌõ¼þµÄÊý¾ÝÁгöÀ´£¬ÎÞÂÛÊý¾Ý¿âÓÐÎÞÖظ´¡£
Ó÷¨Ò²ºÜ¼òµ¥£º
SELECT top 50 from StoreData_200903
UNION ALL
SELECT top 50 from StoreData_200904
ÖµµÃ×¢ÒâµÄÊÇ£¬sql union allµÄÖ´ÐÐЧÂÊÒª±Èsql unionЧÂÊÒª¸ßºÜ¶à£¬ÕâÊÇÒòΪ£¬Ê¹ÓÃsql unionÐèÒª½øÐÐÅÅÖØ£¬¶øsql union All ÊDz»ÐèÒªÅÅÖصģ¬ÕâÒ»µã·Ç³£ÖØÒª£¬ÒòΪ¶ÔÓÚһЩµ¥´¿µØʹÓ÷ֱíÀ´Ìá¸ßЧÂʵIJéѯ£¬ÍêÈ«¿ÉÒÔʹÓÃsql union All¡£
»¹ÓУ¬Èç¹ûʹÓÃÁËunion£¬ÎÞÂÛÊÇsql union»¹ÊÇsql union allÒ»¶¨Òª¼Çס¶ÔÊý¾Ý¿â±í¼ÓÉÏË÷Òý£¡
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ÔÚÊý¾Ý¿âÖУ¬unionºÍunion all ¹Ø¼ü×Ö¶¼Êǽ«Á½¸ö½á¹û¼¯ºÏºÏ²¢ÎªÒ»¸ö£¬µ«ÕâÁ½Õß´ÓʹÓúÍЧÂÊÉÏÀ´Ëµ¶¼ÓÐËù²»Í¬¡£
UNIONÔÚ½øÐбíÁ´½Óºó»áɸѡµôÖظ´µÄ¼Ç¼£¬ËùÒÔÔÚ±íÁ´½Óºó»á¶ÔËù²úÉúµÄ½á¹û¼¯½øÐÐÅÅÐòÔËË㣬ɾ³ýÖظ´µÄ¼Ç¼ÔÙ·µ»Ø½á¹û¡£Êµ¼Ê´ó²¿·ÖÓ¦ÓÃÖÐÊDz»»á²úÉúÖظ´µÄ¼Ç¼£¬×î³£¼ûµÄÊǹý³Ì±íÓëÀúÊ·±íUNION¡£È磺
select * from gc_dfys
union
select * from ls_jg_dfys
Õâ¸öSQLÔÚÔËÐÐʱÏÈÈ¡³öÁ½¸ö±íµÄ½á¹û£¬ÔÙÓÃÅÅÐò¿Õ¼ä½øÐÐÅÅÐòɾ³ýÖظ´µÄ¼Ç¼£¬×îºó·µ»Ø½á¹û¼¯£¬Èç¹û±íÊý¾ÝÁ¿´óµÄ»°¿ÉÄܻᵼÖÂÓôÅÅ̽øÐÐÅÅÐò¡£
¶øUNION ALLÖ»ÊǼòµ¥µÄ½«Á½¸ö½á¹ûºÏ²¢ºó¾Í·µ»Ø¡£ÕâÑù£¬Èç¹û·µ»
Ïà¹ØÎĵµ£º
ת×Ô£º http://hi.baidu.com/beanchx/blog/item/ed056509d66f65cc3bc763f4.html
p6spyµÄÌæ´úÆ·£ºjdbc logger
2007Äê09ÔÂ13ÈÕ ÏÂÎç 01:07
Ê×ÏȽéÉÜÒ»ÏÂÕâ¸ö¿ªÔ´µÄÏîÄ¿¡£Õâ¸öÊÇÒ»¸ö¶ÔjdbcÖеÄsql½øÐÐloggerµÄÒ»¸ö¹¤¾ß¡£ÈôÔÚÏîÄ¿ÖвÉÓÃÁ˽϶àµÄpreparedStatement£¬ÄÇô´òÓ¡³öÀ´µÄsql»áÓкܶà"?"£¬·Ç³£²»·½±ã¡£ÓÐÒ»¸ö²úƷΪp ......
-- ˵Ã÷:
-- 1. Ҫɾ³ý±í table_name, ÐëÏÈÅжϸñíÊÇ·ñÕý±»Êý¾Ý¿âÖÐÆäËü±íËùÒýÓÃ.
-- 2. Èç¹ûδ±»ÒýÓÃ, ¿ÉÖ±½Ó DROP TABLE table_name; ·ñÔò±ØÐëÏÈɾ³ýÒýÓñíµÄÔ¼Êø, ÔÙ DROP TABLE table_name.
-- 3. ÁíÍâ, table_name ÊÇ·ñÕýÒýÓÃÆäËü±íµÄÇé¿öÎÞÐ뿼ÂÇ.
-- ´´½¨Ö÷±í
CREATE TABLE tParent
......
¸ÅÊö
Microsoft SQL Server 2008 ÈÃÄúÄܹ»Í¨¹ýÖ±¹ÛµÄÊý¾ÝÍÚ¾òµÄÔ¤²âÐÔ·ÖÎöÀ´×ö³öÃ÷ÖǺÏÀíµÄ¾ö²ß£¬ÎÞ·ìµØÕûºÏ Microsoft ÉÌÒµÖÇÄÜƽ̨²¢¿ÉÀ©Õ¹ÖÁÉÌÒµÓ¦ÓóÌÐò¡£
ÖØ´óµÄй¦ÄÜ
ͬʱÀûÓôíÎóºÍ¾«È·¶ÈµÄͳ¼Æ·ÖÊýÀ´²âÊÔ¶à¸öÊý¾ÝÍÚ¾òÄ£ÐÍ£¬²¢ÀûÓý»²æÑéÖ¤À´È·ÈÏÆäÎȶ¨ÐÔ
ÔÚµ¥Ò»½á¹¹Öн¨Á¢¶à¸ö²»¼æÈݵÄÍÚ¾òÄ£ÐÍ¡¢ÔÚɸѡ¹ýµÄÊ ......
ÎÄÕµ¼º½ SQL Server 2005 ѧϰ±Ê¼ÇϵÁÐÎÄÕµ¼º½
ÔÚSQl 2005 For XMl ¼òµ¥²éѯ(Raw£¬Auto£¬Pathģʽ)(1) ÀïÎÒÃÇ˵Á˹ØÓÚPath£¬RawºÍAutoģʽµÄÓ÷¨£¬ÆäʵÀïÃæ²»½ö½ö ÊÇÕâЩ¼òµ¥µÄ²Ù×÷£¬»¹ÓÐһЩÆäËüµÄÌØÐÔ£¬±ÈÈç˵Type»òOpenXml·½·¨£¬sp_xml_preparedocument´æ´¢¹ý³Ì µÈÕâЩÔö¼ÓµÄ¶«¶«£¬ÎÒÃÇÀ´Ò» ......
¸ÅÊö
Microsoft SQL Server 2008 ÌṩÁËÓÐÖúÓÚÓÐЧ¹ÜÀí°²È«ÐÔ¹¦ÄÜÅäÖá¢Ç¿Éí·ÝÑéÖ¤ºÍ·ÃÎÊ¿ØÖƵݲȫÐÔÔöÇ¿¹¦ÄÜ¡¢¹¦ÄÜÇ¿´óµÄ¼ÓÃܺÍÃÜÔ¿¹ÜÀí¹¦ÄÜ£¬ÒÔ¼°ÔöÇ¿ÐÍÉóºË¹¦ÄÜ¡£
ÖØ´óµÄй¦ÄÜ
ʹÓûùÓÚ²ßÂԵĹÜÀí£¬Õë¶ÔÆóÒµÄÚµÄÊý¾ÝÀ´¹ÜÀí¼°¼ì²â²»·ûºÏ°²È«²ßÂÔµÄÇé¿ö
²»ÐèÐÞ¸ÄÓ¦ÓóÌÐò¼´¿ÉʹÓÃ͸Ã÷Êý¾Ý¼ÓÃÜÀ´¼ÓÃÜÊý¾Ý
ʹÓÿÉÀ© ......