sqlÖÐand¼°or µÄÖ´ÐÐЧÂÊ
Ó¦ÓÃÖз¢ÏÖsqlÖеÄand¼°orµÄÖ´ÐÐЧÂÊÎÊÌâ
£ó£ñ£ìÓï¾ä£¬ÎªÊ²Ã´°Ñ×îºóµÄ£ï£ò»»³É£á£î£ä£¬²éѯµÄ¾ÍºÜ¿ì£¬Ê¹ÓõÄÊÇmssql·¶ÀýÖÐnorthwindÊý¾Ý¿âΪÀý£¬
select * from Orders a left join [Order Details] b on a.orderid = b.orderid
where a.customerid like '%ics%' or b.productid in (42,72)
×·×ÙÁËÓï¾äµÄÖ´Ðз½°¸,·¢ÏÖʹÓÃor ʱ ÊÇÏÈÖ´ÐеÄa Óëb ½»²æ±í£¬´Ó½á¹û¼¯ÖÐÔÙwhere³ö·ûºÏµÄ¼Ç¼£¬ÓÉÓÚÊÇÈ«¼¯½»²æËùÒÔÊä³öµÄÊý¾ÝÁ¿½Ï´ó,Ö´ÐеÄʱ¼äÒ²¾ÍЧ³¤.
select * from Orders a left join [Order Details] b on a.orderid = b.orderid
where a.customerid like '%ics%' and b.productid in (42,72)
¶øandÊÇÏÈÖ´ÐеÄwhereɸѡ³öÁË·ûºÏµÄ¼Ç¼ÔÙ×öµÄ½»²æ±í,ËùÒÔÊý¾ÝÁ¿ÉÙÖ´ÐÐÆðÀ´¿ì.
Ïà¶ÔÓÚor ΪÁËÌá¸ßÖ´ÐÐËÙ¶È,ÏëÁËÒ»¸ö°ì·¨,ÈçÏÂÈËΪ¿ØÖÆÖ´Ðз½°¸ÏÈɸѡwherºó½»²æleft
set statistics time on
select * from (select * from Orders where customerid like '%ics%') a left join
(select * from [Order Details] b where productid in (42,72)) b on a.orderid = b.orderid
set statistics time off
Ïà¹ØÎĵµ£º
Æô¶¯ÓëÅäÖòÎÊý ¸ü¸ÄϵͳԪÊý¾ÝºÍ²ÎÊýÅäÖà ¶¯Ì¬ÊÓͼ ´æ´¢µÄÎïÀíºÍÂß¼½á¹¹ Æô¶¯ºÍ¹Ø±Õ
topÆô¶¯ÓëÅäÖòÎÊý
ÔÚSQL Server°²×°µÄʱºò£¬Í¬Ê±Ò²»áÍùWindows×¢²á±íÀïÃæÌí¼ÓһЩ¼Ç¼£¬ÕâЩע²á±í¼üÖµÖ¸¶¨ÁËʵÀýËùÐèÒªµÄ¸÷ÖÖ²ÎÊý¡£±ÈÈ磬ÓеÄ×¢²á±í¼üÖµÖ¸¶¨ÁË´íÎóÈÕÖ¾µÄ±£´æĿ¼£¬ÁíÍâµÄÖ¸¶¨ÁËĬÈϵı¸·ÝĿ¼µÈµÈ¡£SQL ServerÔÚÔ ......
Transact-SQL ÓïÑÔʹÓõÄÁ÷³Ì¿ØÖÆÃüÁîÓë³£¼ûµÄ³ÌÐòÉè¼ÆÓïÑÔÀàËÆÖ÷ÒªÓÐÒÔϼ¸ÖÖ¿ØÖÆÃüÁî¡£
4.6.1 IF…ELSE
Æä
Óï·¨ÈçÏ£º
IF <Ìõ¼þ±í´ïʽ>
<ÃüÁîÐлò³ÌÐò¿é>
[ELSE [Ìõ¼þ±í´ïʽ]
<ÃüÁîÐÐ
»ò³ÌÐò¿é>]
ÆäÖÐ<Ìõ¼þ±í´ïʽ>¿ÉÒÔÊǸ÷ÖÖ±í´ïʽµÄ×éºÏ£¬µ«±í´ïʽµÄÖµ±ØÐëÊÇÂß¼Öµ“Õæ&rdq ......
Æäʵɾ³ýÊý¾Ý¿âÖÐÊý¾ÝµÄ·½·¨²¢²»¸´ÔÓ£¬ÎªÊ²Ã´ÎÒ»¹Òª¶à´ËÒ»¾ÙÄØ£¬Ò»ÊÇÎÒÕâÀï½éÉܵÄÊÇɾ³ýÊý¾Ý¿âµÄËùÓÐÊý¾Ý£¬ÒòΪÊý¾ÝÖ®¼ä¿ÉÄÜÐγÉÏ໥ԼÊø¹Øϵ£¬É¾³ý²Ù×÷¿ÉÄÜÏÝÈëËÀÑ»·£¬¶þÊÇÕâÀïʹÓÃÁË΢ÈíδÕýʽ¹«¿ªµÄsp_MSForEachTable´æ´¢¹ý³Ì¡£
Ò²ÐíºÜ¶à¶ÁÕßÅóÓѶ¼¾Àú¹ýÕâÑùµÄÊÂÇ飺ҪÔÚ¿ª·¢Êý¾Ý¿â»ù´¡ÉÏÇåÀíÒ»¸ö¿Õ¿â£¬µ«ÓÉÓÚ¶ÔÊý¾Ý¿ ......
Ëø»úÖÆ
NOLOCKºÍREADPASTµÄÇø±ð¡£
1. ¿ªÆôÒ»¸öÊÂÎñÖ´ÐвåÈëÊý¾ÝµÄ²Ù×÷¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'a','a'
2. Ö´ÐÐÒ»Ìõ²éѯÓï¾ä¡£
SELECT * from Customer WITH (NOLOCK)
½á¹ûÖÐÏÔʾ"a"ºÍ"a"¡£µ±1ÖÐÊÂÎñ»Ø¹öºó£¬ÄÇôa½«³ÉΪÔàÊý¾Ý¡£(×¢:1ÖеÄÊÂÎñδÌá½») ¡£NOLOCK±íÃ÷ûÓжÔÊý¾Ý±íÌí¼Ó¹²Ï ......