SQL ServerÊÓͼÖг£見ÏÞÖÆÌõ¼þ
--> Title : SQL ServerÊÓͼÖг£見ÏÞÖÆÌõ¼þ
--> Author : wufeng4552
--> Date : 2010-03-01
(1): ÊÓͼÊý¾Ý¸ü¸ÄµÄ³£見ÏÞ¶¨
µ±Óû§¸üÐÂÊÓͼÖеÄÊý¾Ýʱ,Æäʵ¸ü¸ÄµÄÊÇÆä¶ÔÓ¦µÄÊý¾Ý±íµÄÊý¾Ý.ÎÞÂÛÊǶÔÊÓͼÖеÄÊý¾Ý½øÐиü¸Ä,»¹ÊÇÔÚÊÓͼÖвåÈë»òÕßɾ³ýÊý¾Ý,¶¼ÊÇÀàËƵĵÀÀí.µ«ÊÇ,²»ÊÇËùÓÐÊÓͼ¶¼¿ÉÒÔ½øÐиü¸Ä.ÈçÏÂÃæµÄÕâЩÊÓͼ,ÔÚSQL ServerÊý¾Ý¿âÖоͲ»Äܹ»Ö±½Ó¶ÔÆäÄÚÈݽøÐиüÐÂ,·ñÔò,ϵͳ»á¾Ü¾øÕâÖÖ·Ç·¨µÄ²Ù×÷.
(1.1) Group By×Ó¾ä
ÈçÔÚÒ»¸öÊÓͼÖУ¬Èô²ÉÓÃGroup By×Ӿ䣬¶ÔÊÓͼÖеÄÄÚÈݽøÐÐÁË»ã×Ü¡£ÔòÓû§¾Í²»Äܹ»¶ÔÕâÕÅÊÓͼ½øÐиüС£ÕâÖ÷ÒªÊÇÒòΪ²ÉÓÃGroup By×Ó¾ä¶Ô²éѯ½á¹û½øÐлã×ÜÔÚºó£¬ÊÓͼÖоͻᶪʧÕâÌõ¼Í¼µÄÎïÀí´æ´¢Î»Öá£Èç´Ë£¬ÏµÍ³¾ÍÎÞ·¨ÕÒµ½ÐèÒª¸üеļͼ¡£ÈôÓû§ÏëÒªÔÚÊÓͼÖиü¸ÄÊý¾Ý£¬ÔòÊý¾Ý¿â¹ÜÀíÔ±¾Í²»Äܹ»ÔÚÊÓͼÖÐÌí¼ÓÕâ¸öGroup BY·Ö×éÓï¾ä¡£
(1.2) Distinct¹Ø¼ü×Ö
Èç²»Äܹ»Ê¹ÓÃDistinct¹Ø¼ü×Ö¡£Õâ¸ö¹Ø¼ü×ÖµÄÓÃ;¾ÍÊÇÈ¥³ýÖظ´µÄ¼Í¼¡£ÈçûÓÐÌí¼ÓÕâ¸ö¹Ø¼ü×ÖµÄʱºò£¬ÊÓͼ²éѯ³öÀ´µÄ¼Í¼ÓÐ250Ìõ¡£Ìí¼ÓÁËÕâ¸ö¹Ø¼ü×Öºó£¬Êý¾Ý¿â¾Í»áÌÞ³ýÖظ´µÄ¼Í¼£¬Ö»ÏÔʾ²»Öظ´µÄ50Ìõ¼Í¼¡£´Ëʱ£¬ÈôÓû§Òª¸Ä±äÆäÖÐÒ»¸öÊý¾Ý£¬ÔòÊý¾Ý¿â¾Í²»ÖªµÀÆäµ½µ×ÐèÒª¸ü¸ÄÄÄÌõ¼Í¼¡£ÒòΪÊÓͼÖп´ÆðÀ´Ö»ÓÐÒ»Ìõ¼Í¼£¬¶øÔÚ»ù´¡±íÖпÉÄܶÔÓеļͼÓм¸Ê®Ìõ¡£Îª´Ë£¬ÈôÔÚÊÓͼÖвÉÓÃÁËDistinct¹Ø¼ü×ֵĻ°£¬¾ÍÎÞ·¨¶ÔÊÓͼÖеÄÄÚÈݽøÐиü¸Ä¡£
(1.3) AVG¡¢MAXµÈº¯Êý
Èç¹ûÔÚÊÓͼÖÐÓÐAVG¡¢MAXµÈº¯Êý£¬ÔòÒ²²»Äܹ»¶ÔÆä½øÐиüС£ÈçÔÚÒ»ÕÅÊÓͼÖУ¬Æä²ÉÓÃÁËSUNº¯ÊýÀ´»ã×ÜÔ±¹¤µÄ¹¤×Êʱ£¬´Ëʱ£¬¾Í²»Äܹ»¶ÔÕâÕűí½øÐиüС£ÕâÊÇÊý¾Ý¿âΪÁ˱£ÕÏÊý¾ÝÒ»ÖÂÐÔËùÌí¼ÓµÄÏÞÖÆÌõ¼þ¡£
С結: ¿É¼û£¬ÊÔͼËäÈ»·½±ã¡¢°²È«£¬µ«ÊÇ£¬ÆäÈÔÈ»²»Äܹ»´úÌæ±íµÄµØλ¡£µ±ÐèÒª¶ÔһЩ±íÖеÄÊý¾Ý½øÐиüÐÂʱ£¬ÎÒÃÇÍùÍù¸ü¶àµÄͨ¹ý¶Ô±íµÄ²Ù×÷À´Íê³É¡£ÒòΪ¶ÔÊÓͼÄÚÈݽøÐÐÖ±½Ó¸ü¸ÄµÄ»°£¬ÐèÒª×ñÊØһЩÏÞÖÆÌõ¼þ¡£ÔÚʵ¼Ê¹¤×÷ÖУ¬¸ü¶àµÄ´¦Àí¹æÔòÊÇͨ¹ýǰ̨³ÌÐòÖ±½Ó¸ü¸Äºǫ́»ù´¡±í¡£ÖÁÓÚÕâЩ±íÖÐÊý¾ÝµÄ°²È«ÐÔ£¬ÔòÒªÒÀ¿¿Ç°Ì¨Ó¦ÓóÌÐòÀ´±£»¤¡£È·±£¸ü¸ÄµÄ׼ȷÐÔ¡¢ºÏ·¨ÐÔ¡£
(2): ¶¨ÒåÊÓͼµÄ²éѯÓï¾äÖв»Äܹ»Ê¹ÓÃijЩ¹Ø¼ü×Ö
(2.1) ²»Äܹ»´øÓÐInto¹Ø¼ü×Ö
ÎÒÃǶ¼ÖªµÀ£¬ÊÓͼÆäʵ¾ÍÊÇÒ»×é²éѯÓï¾ä×é³É¡£»òÕß˵£¬ÊÓͼÊÇ·â×°²éѯÓï¾äµÄÒ»¸ö¹¤¾ß¡£ÔÚ²éѯÓï¾äÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýһЩ¹Ø¼ü×ÖÀ´¸ñʽ»¯ÏÔʾµÄ½á¹û¡£ÈçÎÒÃÇÔÚƽʱ¹¤×÷ÖУ¬¾³£»áÐèÒª°ÑijÕűíÖеÄÊý¾Ý¸úÁíÍâÒ»Õűí½øÐкϲ¢¡£´
Ïà¹ØÎĵµ£º
sql ´úÂë:
---------------------------------------------------------
/*
a ±íÃû
Èç¹ûÔÚsql ²éѯ·ÖÎöÆ÷µ±ÖгöÏÖ
" SQL Server ×èÖ¹Á˶Ô×é¼þ 'xp_cmdshell' µÄ ¹ý³Ì'sys.xp_cmdshell' µÄ·ÃÎÊ£¬ÒòΪ´Ë×é¼þÒÑ×÷Ϊ´Ë·þÎñÆ÷°²È«ÅäÖõÄÒ»²¿·Ö¶ø±»¹Ø± ......
תÔØÒ»¸öBDBµÄÏà¹Ø½éÉÜ£¬»ù±¾¿ÉÒÔµ±ËÙ³ÉÊÖ²áÓ㬸ü¶àµÄÎĵµ¿ÉÒÔÈ¥Oracle¹Ù·½ÍøÕ¾ÏÂÔØ¡£
SQL ¿ª·¢ÈËÔ± Oracle Berkeley DB Ö¸ÄÏ
×÷ÕߣºMargo Seltzer
Oracle Berkeley DB Öг£Óà SQL º¯ÊýʹÓÃÖ¸ÄÏ¡£
2007 Äê 9 Ô·¢±í
³£³£ÓÐÈËÎÊ Oracle Berkeley DB “ÎÒÈçºÎÔÚ Berkeley DB ÖнøÐÐ <SQL ²éѯ>£¿"Òò´Ë£¬ÎÒÃÇ ......
db2 µ÷ÓÃsql½Å±¾³£ÓÃÃüÁdb2 -tf d:\creat_table.sql Óë db2 -td$ -f d:\creat_table.sql
db2 -tf d:\creat_table.sql µ÷Óýű¾ÃüÁîÊÇddl²Ù×÷
µ±Óöµ½sqlÓï¾ä¹ý³¤£¬»òÌáʾ DB21007E ¶ÁÈ¡¸ÃÃüÁîʱÒѵ½´ïÎļþĩβ¡£¾ÍʹÓà db2 -td$ -f d:\creat_table.sql ÃüÁî
ʹÓøÄÃüÁîÐèÒªÔÚsql½Å±¾ÖÐÒÔ$½áÊ ......
µ¼³ö.sqlÎļþ
1.½«Êý¾Ý¿âtransfer_server_dbµ¼³öµ½transfSRV.sqlÎļþÖУº
mysqldump -u root -p transfer_server_db > /home/eric/transfSRV.sql
2.½«Êý¾Ý¿âtransfer_server_dbÖеÄdevice_info_tableµ¼³öµ½table.sqlÎļþÖУº
mysqldump -u root -p transfer_server_db device_info_table > /home/eric/ta ......
ÈçºÎÔ¶³ÌÅжÏOracleÊý¾Ý¿âµÄ°²×°Æ½Ì¨
¡¡¡¡select * from v$version;
¡¡¡¡²é¿´±í¿Õ¼äµÄʹÓÃÇé¿ö
¡¡¡¡select sum(bytes)/(1024*1024) as free_space,tablespace_name
¡¡¡¡from dba_free_space
¡¡¡¡group by tablespace_name;
¡¡¡¡SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES ......