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

SQl Cookbookѧϰ±Ê¼Ç

1.select  * from A where a.a='a';
  Ö´ÐÐ˳Ðò ÏÈÖ´ÐÐ from ÔÚÖ´ÐÐ where ÖеĶ«Î÷ £¬×îºóÖ´ÐÐ select
2.ÁÐÖµÁ¬½Ó db2 oracle ||  , mysql concat(column1,'sss',column2) sqlServlerʹÓÃ+Á¬½Ó;
3. case when  ±í´ïʽ then ''
            when  ±í´ïʽ then ''
             else    ''
   end
4. ÏÞÖÆ·µ»ØµÄÐÐÊý
 ÔÚoracleÖÐʹÓÃrownum <= n ÏÞÖÆÐÐÊý
 ÔÚdb2ÖÐʹÓÃfetch first 5 rows only
 ×¢Òâ oracleÖÐÈç¹ûʹÓÃrownum =5 Êǵò»µ½µÚÎåÐеģ¬ÒòΪoracleµÄ²éѯԭÀí»ñÈ¡Ò»Ðк󸳸øÐкţ¬Èç¹ûÐкÅÂú×ãÌõ¼þ·µ»Ø·ñÔòÉáÆú£¬ÕâÑùÓÀÔ¶µÃ²»µ½µÚÎåÐУ¬ÓÀÔ¶ÊǵÚÒ»ÐкŲ¢½ÓÉáÆú£¬ËùÒÔÒªÏëµÃµ½µÚÎåÐУ¬±ØÐëµÃµ½Ç°ËÄÐУ¬ËùÒÔ²éѯǰÎåÐбØÐëÊÇ<= 5;
5.null ÒªÏëÅжÏÖµÊÇ·ñΪnull±ØÐëΪ is null  £¬ null²»ÄÜÓõÈÓÚ=ºÍ²»µÈÓÚ<> ºÍÈκÎÖµ±È½Ï°üÀ¨null
6¡£°´Ä£Ê½²éѯ like '%a' 


Ïà¹ØÎĵµ£º

¡¾×ª¡¿´ø´æÔÚÁ¿´ÊNOT EXISTSµÄSQLÓï¾äÎÊÌâ

´ø´æÔÚÁ¿´ÊNOT EXISTSµÄSQLÓï¾äÎÊÌâ
ѧÉú±ístudent (snoѧºÅ snameÐÕÃû sdeptËùÔÚϵ)
¿Î³Ì±ícourse (cno¿Î³ÌºÅ cname¿Î³ÌÃû cpnoÑ¡Ð޿κŠccreditѧ·Ö)
ѧÉúÑ¡¿Î±ísc (sn0ѧºÅ cno¿Î³ÌºÅ grade³É¼¨)
¶ÔÒÔÉϱí½øÐвéÑ°Ñ¡ÐÞÁËÈ«²¿¿Î³ÌµÄѧÉúÐÕÃû
ÓÉÓÚ²»£¬Ã»ÓÐÈ«³ÆÁ¿´Ê£¬¿É½«ÌâÄ¿µÄÒâ˼ת»»ÎªµÈ¼ÛµÄ´æÔÚÁ¿´ÊÐÎʽ£º²éÑ ......

½²½âMSSQLÊý¾Ý¿âÖÐSQLËø»úÖƺÍÊÂÎñ¸ôÀ뼶±ð

Ëø»úÖÆ
NOLOCKºÍREADPASTµÄÇø±ð¡£
1. ¿ªÆôÒ»¸öÊÂÎñÖ´ÐвåÈëÊý¾ÝµÄ²Ù×÷¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'a','a'
2. Ö´ÐÐÒ»Ìõ²éѯÓï¾ä¡£
SELECT * from Customer WITH (NOLOCK)
½á¹ûÖÐÏÔʾ"a"ºÍ"a"¡£µ±1ÖÐÊÂÎñ»Ø¹öºó£¬ÄÇôa½«³ÉΪÔàÊý¾Ý¡£(×¢:1ÖеÄÊÂÎñδÌá½») ¡£NOLOCK±íÃ÷ûÓжÔÊý¾Ý±íÌí¼Ó¹²Ï ......

SQLÃüÁî´óÈ« ÖÐÓ¢ÎĶÔÕÕ

[code=SQL][/code]
--Óï ¾ä ¹¦ ÄÜ 
--Êý¾Ý²Ù×÷ 
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁР
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐР
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐР
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý 
--Êý¾Ý¶¨Òå 
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í 
DROP TABLE --´ÓÊý¾Ý ......

SQL×Ó²éѯʵÀý

×Ó²éѯÊÇÔÚÒ»¸ö²éѯÄڵIJéѯ¡£×Ó²éѯµÄ½á¹û±»DBMSʹÓÃÀ´¾ö¶¨°üº¬Õâ¸ö×Ó²éѯµÄ¸ß¼¶²éѯµÄ½á¹û¡£ÔÚ×Ó²éѯµÄ×î¼òµ¥µÄÐÎʽÖУ¬×Ó²éѯ³ÊÏÖÔÚÁíÒ»ÌõSQLÓï¾äµÄWHERE»òHAVING×Ó¾ÖÄÚ¡£ 
    ÁгöÆäÏúÊÛÄ¿±ê³¬¹ý¸÷¸öÏúÊÛÈËÔ±¶¨¶î×ۺϵÄÏúÊ۵㡣
SELECT CITY
from OFFICES
WHERE TARGET&nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ