SQLÓï¾ä´ó·¨
SQLÓïÑÔÓÉÃüÁî¡¢×Ӿ䡢ÔËËãºÍ¼¯ºÏº¯ÊýµÈ¹¹³É¡£ÔÚSQLÖУ¬Êý¾Ý¶¨ÒåÓïÑÔDDL£¨ÓÃÀ´½¨Á¢¼°¶¨ÒåÊý¾Ý±í¡¢×Ö¶ÎÒÔ¼°Ë÷ÒýµÈÊý¾Ý¿â½á¹¹£©°üº¬µÄÃüÁîÓÐCREATE¡¢DROP¡¢ALTER£»Êý¾Ý²Ù×ÝÓïÑÔDML£¨ÓÃÀ´ÌṩÊý¾ÝµÄ²éѯ¡¢ÅÅÐòÒÔ¼°É¸Ñ¡Êý¾ÝµÈ¹¦ÄÜ£©°üº¬µÄÃüÁîÓÐSELECT¡¢INSERT¡¢UPDATE¡¢DELETE¡£
Ò»¡¢SQLÓï¾ä
£¨1£©Select ²éѯÓï¾ä
Óï·¨£ºSELECT [ALL|DISTINCT] <Ä¿±êÁбí´ïʽ> [AS ÁÐÃû]
[,<Ä¿±êÁбí´ïʽ> [AS ÁÐÃû] ...] from <±íÃû> [£¬<±íÃû>…]
[WHERE <Ìõ¼þ±í´ïʽ> [AND|OR <Ìõ¼þ±í´ïʽ>...]
[GROUP BY ÁÐÃû [HAVING <Ìõ¼þ±í´ïʽ>>
[ORDER BY ÁÐÃû [ASC | DESC>
½âÊÍ£º[ALL|DISTINCT] ALL£ºÈ«²¿£» DISTINCT£º²»°üÀ¨Öظ´ÐÐ
<Ä¿±êÁбí´ïʽ> ¶Ô×ֶοÉʹÓÃAVG¡¢COUNT¡¢SUM¡¢MIN¡¢MAX¡¢ÔËËã·ûµÈ
<Ìõ¼þ±í´ïʽ>
²éѯÌõ¼þ ν´Ê
±È½Ï =¡¢>,<,>=,<=,!=,<>,
È·¶¨·¶Î§ BETWEEN AND¡¢NOT BETWEEN AND
È·¶¨¼¯ºÏ IN¡¢NOT IN
×Ö·ûÆ¥Åä LIKE£¨“%”Æ¥ÅäÈκγ¤¶È£¬“_”Æ¥ÅäÒ»¸ö×Ö·û£©¡¢NOT LIKE
¿ÕÖµ IS NULL¡¢IS NOT NULL
×Ó²éѯ ANY¡¢ALL¡¢EXISTS
¼¯ºÏ²éѯ UNION£¨²¢£©¡¢INTERSECT£¨½»£©¡¢MINUS£¨²î£©
¶àÖØÌõ¼þ AND¡¢OR¡¢NOT
<GROUP BY ÁÐÃû> ¶Ô²éѯ½á¹û·Ö×é
[HAVING <Ìõ¼þ±í´ïʽ>] ·Ö×éɸѡÌõ¼þ
[ORDER BY ÁÐÃû [ASC | DESC> ¶Ô²éѯ½á¹ûÅÅÐò£»ASC£ºÉýÐò DESC£º½µÐò
Àý1£º select student.sno as ѧºÅ, student.name as ÐÕÃû, course as ¿Î³ÌÃû, score as ³É¼¨ from score,student where student.sid=score.sid and score.sid=:sid
Àý2£ºselect student.sno as ѧºÅ, student.name as ÐÕÃû,AVG(score) as ƽ¾ù·Ö from score,student where student.sid=score.sid and student.class=:class and (term=5 or term=6) group by student.sno, student.name having count(*)>0 order by ƽ¾ù·Ö DESC
Àý3£ºselect * from score where sid like '9634'
Àý4£ºselect * from student where class in (select class from student where name='³ÂСС')
£¨2£©INSERT²åÈëÓï¾ä
Óï·¨£ºINSERT INTO <±íÃû> [£¨<×Ö¶ÎÃû1> [,<×Ö¶ÎÃû2>, ...])] VALUES (<³£Á¿1> [,<³£Á¿2>, ...])
Óï·¨£ºINSERT INTO <±íÃû> [£¨<×Ö¶ÎÃû1> [,<×Ö¶ÎÃû2>, ...])] ×Ó²éѯ
Àý×Ó£ºINSERT INTO ½è
Ïà¹ØÎĵµ£º
--> Title : SQL Server²é詢¿ÉÓôÅÅÌ¿Õ¼ä
--> Author : wufeng4552
--> Date : 2009-10-30 09:59:09
Ç°ÑÔ
Èç¹ûÄãµÄ×éÖ¯ÓµÓеijÌÐòÒªÇóÒ»¸öºÜ´óÁ¿µÄ´ÅÅÌ¿Õ¼ä»òÕß´ó±ÈÀýµÄÌض¨´ÅÅÌ£¬ÄÇôȷ±£ÔÚ³ÌÐò¿ªÊ¼»òÕ߹ؼüµãʱȷÈÏ´ÅÅÌÇý¶¯Æ÷¾ßÓÐ×ã¹»µÄ´æ´¢¡£Ò»´Î¿ìËÙ¼ì²é¾Í¿ÉÒÔ½ÚÔ¼´óÁ¿µÄʱ¼ä£¬¼õ ......
SUBSTRING
·µ»Ø×Ö·û¡¢binary¡¢text »ò image ±í´ïʽµÄÒ»²¿·Ö¡£ÓйؿÉÓë¸Ãº¯ÊýÒ»ÆðʹÓõÄÓÐЧ Microsoft® SQL Server ......
--´´½¨Óαê
DECLARE Cursor1 CURSOR FOR
SELECT NODE_NO,NODE_VALUE,SUM(RESALE_SUM-RESALERETU_SUM+SALE_SUM-SALERETU_SUM) sale_sum,
SUM(STORE_SUM) sum_store,SUM(STORE_SUM) store_sum,
sum(RESALE_PROFIT-RESALERETU_PROFIT+SALE_PROFIT-SALERETU_PROFIT-ADJUST_PROFIT) sale_profit
from ......
¹Ì¶¨ÈÕÆÚ¼õÒ»¸öÔ£¨ÈÕ¡¢Ä꣩
dateadd(±í´ïʽ1£¬±í´ïʽ2£¬±í´ïʽ3£©
±í´ïʽ1ΪMM»òYY»òDD
±í´ïʽ2Ϊ1
±í´ïʽ3ΪҪ¼õµÄÈÕÆÚ Ò»¸öÔµĵÚÒ»Ìì µÚÒ»¸öÀý×Ó£¬ÎÒ½«¸æËßÄãÈçºÎ´Óµ±Ç°ÈÕÆÚÈ¥Õâ¸öÔµÄ×îºóÒ»Ìì¡£Çë×¢Ò⣺Õâ¸öÀý×ÓÒÔ¼°ÕâƪÎÄÕÂÖеÄÆäËûÀý×Ó¶¼½«Ö»Ê¹ÓÃDATEDIFFºÍDATEADDº¯ÊýÀ´¼ÆËãÎÒÃÇÏëÒªµÄÈÕ ......
--> Title : SQL Server 2005EXCEPTºÍINTERSECTÔËËã·û
--> Author : wufeng4552
--> Date : 2009-10-30
(Ò»)¸ÅÄî
EXCEPTºÍINTERSECTÔËËã·ûʹÄú¿ÉÒԱȽÏÁ½¸ö»ò¶à¸öSELECTÓï¾äµÄ½á¹û²¢·µ»Ø·ÇÖظ´Öµ¡£
(¶þ)區別
EXCEPTÔËËã·û·µ»ØÓÉEXCEPTÔËËã·û×ó²àµÄ²éѯ·µ»Ø¡¢¶øÓÖ² ......