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Óï¾äÎÊÌâ
ѧÉú±ístudent (snoѧºÅ snameÐÕÃû sdeptËùÔÚϵ)
¿Î³Ì±ícourse (cno¿Î³ÌºÅ cname¿Î³ÌÃû cpnoÑ¡Ð޿κŠccreditѧ·Ö)
ѧÉúÑ¡¿Î±ísc (sn0ѧºÅ cno¿Î³ÌºÅ grade³É¼¨)
¶ÔÒÔÉϱí½øÐвéÑ°Ñ¡ÐÞÁËÈ«²¿¿Î³ÌµÄѧÉúÐÕÃû
ÓÉÓÚ²»£¬Ã»ÓÐÈ«³ÆÁ¿´Ê£¬¿É½«ÌâÄ¿µÄÒâ˼ת»»ÎªµÈ¼ÛµÄ´æÔÚÁ¿´ÊÐÎʽ£º²éÑ ......
Ëø»úÖÆ
NOLOCKºÍREADPASTµÄÇø±ð¡£
1. ¿ªÆôÒ»¸öÊÂÎñÖ´ÐвåÈëÊý¾ÝµÄ²Ù×÷¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'a','a'
2. Ö´ÐÐÒ»Ìõ²éѯÓï¾ä¡£
SELECT * from Customer WITH (NOLOCK)
½á¹ûÖÐÏÔʾ"a"ºÍ"a"¡£µ±1ÖÐÊÂÎñ»Ø¹öºó£¬ÄÇôa½«³ÉΪÔàÊý¾Ý¡£(×¢:1ÖеÄÊÂÎñδÌá½») ¡£NOLOCK±íÃ÷ûÓжÔÊý¾Ý±íÌí¼Ó¹²Ï ......
[code=SQL][/code]
--Óï ¾ä ¹¦ ÄÜ
--Êý¾Ý²Ù×÷
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE --´ÓÊý¾Ý ......
×Ó²éѯÊÇÔÚÒ»¸ö²éѯÄڵIJéѯ¡£×Ó²éѯµÄ½á¹û±»DBMSʹÓÃÀ´¾ö¶¨°üº¬Õâ¸ö×Ó²éѯµÄ¸ß¼¶²éѯµÄ½á¹û¡£ÔÚ×Ó²éѯµÄ×î¼òµ¥µÄÐÎʽÖУ¬×Ó²éѯ³ÊÏÖÔÚÁíÒ»ÌõSQLÓï¾äµÄWHERE»òHAVING×Ó¾ÖÄÚ¡£
ÁгöÆäÏúÊÛÄ¿±ê³¬¹ý¸÷¸öÏúÊÛÈËÔ±¶¨¶î×ۺϵÄÏúÊ۵㡣
SELECT CITY
from OFFICES
WHERE TARGET&nbs ......