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

SQLÓï¾äÓÅ»¯


ÎÒÃÇÒª×öµ½²»µ«»áдSQL,»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQL,ÒÔÏÂΪ±ÊÕßѧϰ¡¢ÕªÂ¼¡¢²¢»ã×ܲ¿·Ö×ÊÁÏÓë´ó¼Ò·ÖÏí£¡
£¨1£©Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
orACLEµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, ÄǾÍÐèҪѡÔñ½»²æ±í(intersection table)×÷Ϊ»ù´¡±í, ½»²æ±íÊÇÖ¸ÄǸö±»ÆäËû±íËùÒýÓõıí.
£¨2£©Where×Ó¾äÖеÄÁ¬½Ó˳Ðò£®£º
orACLE²ÉÓÃ×Ô϶øÉϵÄ˳Ðò½âÎöWhere×Ó¾ä,¸ù¾ÝÕâ¸öÔ­Àí,±íÖ®¼äµÄÁ¬½Ó±ØÐëдÔÚÆäËûWhereÌõ¼þ֮ǰ, ÄÇЩ¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐëдÔÚWhere×Ó¾äµÄĩβ.
£¨3£©Select×Ó¾äÖбÜÃâʹÓà ‘ * ‘£º
orACLEÔÚ½âÎöµÄ¹ý³ÌÖÐ, »á½«'*' ÒÀ´Îת»»³ÉËùÓеÄÁÐÃû, Õâ¸ö¹¤×÷ÊÇͨ¹ý²éѯÊý¾Ý×ÖµäÍê³ÉµÄ, ÕâÒâζ׎«ºÄ·Ñ¸ü¶àµÄʱ¼ä
£¨4£©¼õÉÙ·ÃÎÊÊý¾Ý¿âµÄ´ÎÊý£º
orACLEÔÚÄÚ²¿Ö´ÐÐÁËÐí¶à¹¤×÷: ½âÎöSQLÓï¾ä, ¹ÀËãË÷ÒýµÄÀûÓÃÂÊ, °ó¶¨±äÁ¿ , ¶ÁÊý¾Ý¿éµÈ£»
£¨5£©ÔÚSQL*Plus , SQL*FormsºÍPro*CÖÐÖØÐÂÉèÖÃARRAYSIZE²ÎÊý, ¿ÉÒÔÔö¼Óÿ´ÎÊý¾Ý¿â·ÃÎʵļìË÷Êý¾ÝÁ¿ ,½¨ÒéֵΪ200
£¨6£©Ê¹ÓÃDECODEº¯ÊýÀ´¼õÉÙ´¦Àíʱ¼ä£º
ʹÓÃDECODEº¯Êý¿ÉÒÔ±ÜÃâÖظ´É¨ÃèÏàͬ¼Ç¼»òÖظ´Á¬½ÓÏàͬµÄ±í.
£¨7£©ÕûºÏ¼òµ¥,ÎÞ¹ØÁªµÄÊý¾Ý¿â·ÃÎÊ£º
Èç¹ûÄãÓм¸¸ö¼òµ¥µÄÊý¾Ý¿â²éѯÓï¾ä,Äã¿ÉÒÔ°ÑËüÃÇÕûºÏµ½Ò»¸ö²éѯÖÐ(¼´Ê¹ËüÃÇÖ®¼äûÓйØϵ)
£¨8£©É¾³ýÖظ´¼Ç¼£º
×î¸ßЧµÄɾ³ýÖظ´¼Ç¼·½·¨ ( ÒòΪʹÓÃÁËROWID)Àý×Ó£º
Delete  from  EMP E  Where  E.ROWID > (Select MIN(X.ROWID)
from  EMP X  Where  X.EMP_NO = E.EMP_NO);
£¨9£©ÓÃTRUNCATEÌæ´úDelete£º
µ±É¾³ý±íÖеļǼʱ,ÔÚͨ³£Çé¿öÏÂ, »Ø¹ö¶Î(rollback segments ) ÓÃÀ´´æ·Å¿ÉÒÔ±»»Ö¸´µÄÐÅÏ¢. Èç¹ûÄãûÓÐCOMMITÊÂÎñ,ORACLE»á½«Êý¾Ý»Ö¸´µ½É¾³ý֮ǰµÄ״̬(׼ȷµØ˵Êǻָ´µ½Ö´ÐÐɾ³ýÃüÁî֮ǰµÄ×´¿ö) ¶øµ±ÔËÓÃTRUNCATEʱ, »Ø¹ö¶Î²»ÔÙ´æ·ÅÈκοɱ»»Ö¸´µÄÐÅÏ¢.µ±ÃüÁîÔËÐкó,Êý¾Ý²»Äܱ»»Ö¸´.Òò´ËºÜÉÙµÄ×ÊÔ´±»µ÷ÓÃ,Ö´ÐÐʱ¼äÒ²»áºÜ¶Ì. (ÒëÕß°´: TRUNCATEÖ»ÔÚɾ³ýÈ«±íÊÊÓÃ,TRUNCATEÊÇDDL²»ÊÇDML)
£¨10£© ¾¡Á¿¶àʹÓÃCOMMIT£º
Ö»ÒªÓпÉÄÜ,ÔÚ³ÌÐòÖо¡Á¿¶àʹÓÃCOMMIT, ÕâÑù³ÌÐòµÄÐÔÄܵõ½Ìá¸ß,ÐèÇóÒ²»áÒòΪCOMMITËùÊͷŵÄ×ÊÔ´¶ø¼õÉÙ:
COMMITËùÊͷŵÄ×ÊÔ´:
a. »Ø¹ö¶ÎÉÏÓÃÓÚ»Ö¸


Ïà¹ØÎĵµ£º

accessÓëSqlServer ֮ʱ¼äÓëÈÕÆÚ¼°ÆäËüSQLÓï¾ä±È½Ï

1¡¢Datediff£º
1.1Ëã³öÈÕÆڲ
1.access:       datediff('d',fixdate,getdate())
2.sqlserver:    datediff(day,fixdate,getdate())
ACCESSʵÀý£º    select * from table where data=datediff('d',fixdate,getdate())
sqlserverʵÀý£º select * from ......

¡¾¸´Ï°¡¿SQL ÄÚ£¬Í⣬×ó£¬ÓÒÁ¬½Ó

ÐÅÏ¢±í(infor)¹¤×ʱí(pay)
ÄÚÁ¬½Ó
select pay.name,infor.AGE,PAY.MONEY,infor.email from pay  join infor on infor.name=PAY.name
×óÍâÁ¬½Ó
select pay.name,infor.AGE,PAY.MONEY,infor.email from pay  left join infor on infor.name=PAY.name
PS£º½á¹ûÓÐÍõÎ壬¹¤×ÊΪ0
ÓÒÍâÁ¬½Ó
select pay.name,info ......

SQL CASEµÄÓ÷¨£¬±ÈÏëÏóÖеÄÇ¿´ó

±íÈçÏÂ
Ò»ÌõÓï¾äÏÔʾËùÓдóÓÚ25ËêºÍϵÄÈË£¬ÒÔÉϵÄÈËÏÔ'´óÁä'
select case when age>25 then '´óÁä' else 'СÁä' end as ÄêÁ伶±ð,count(*) as ÈËÊý from infor group by case when age>25 then '´óÁä' else 'СÁä' end
  ......

[zz]Ê®ÖÖ¿ªÔ´µÄsql¿Í»§¶Ë

SQL¿Í»§¶ËÊÇÿ¸ö¿ª·¢ÈËÔ±ËùÐèµÄ±Ø²»¿ÉÉٵŤ¾ß¡£ËûÃÇ°ïÖú¿ª·¢ÈËÔ±ÇáËɵØÔÚÈκÎÊý¾Ý¿âÖ´ÐÐSQL²éѯ¡£ËüÃǶÔÓÚ½â¾öÈκÎÊý¾Ý¿âÏà¹ØµÄÎÊÌâÒ²ÊǷdz£ÖØÒªµÄ¡£
        1. SQuirreL SQL Client
        SQuirreL SQL ClientÊÇÄ¿Ç°×îÁ÷ÐеĿªÔ´SQL¿Í»§¶Ë¡£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ