SQL ServerË÷Òý¹ÜÀíÖ®Áù´óÌúÂÉ
ÔÎÄת×Ô:http://tech.it168.com/a2009/0218/265/000000265868.shtml
Ë÷ÒýÊÇÒÔ±íÁÐΪ»ù´¡µÄÊý¾Ý¿â¶ÔÏó¡£Ë÷ÒýÖб£´æ×űíÖÐÅÅÐòµÄË÷ÒýÁУ¬²¢ÇҼͼÁËË÷ÒýÁÐÔÚÊý¾Ý¿â±íÖеÄÎïÀí´æ´¢Î»Öã¬ÊµÏÖÁ˱íÖÐÊý¾ÝµÄÂß¼ÅÅÐò¡£Í¨¹ýË÷Òý£¬¿ÉÒÔ¼Ó¿ìÊý¾ÝµÄ²éѯËٶȺͼõÉÙϵͳµÄÏìӦʱ¼ä;¿ÉÒÔʹ±íºÍ±íÖ®¼äµÄÁ¬½ÓËٶȼӿ졣
µ«ÊÇ£¬²»ÊÇÔÚÈκÎʱºòʹÓÃË÷Òý¶¼Äܹ»´ïµ½ÕâÖÖЧ¹û¡£ÈôÔÚ²»Ç¡µ±µÄ³¡ºÏÏ£¬Ê¹ÓÃË÷Òý·´¶ø»áÊÂÓëԸΥ¡£ËùÒÔ£¬ÔÚSQL ServerÊý¾Ý¿âÖÐʹÓÃË÷ÒýµÄ»°£¬»¹ÊÇÐèÒª×ñÊØÒ»¶¨µÄ¹æÔò¡£
ÌúÂÉÒ»£ºÌìÏÂûÓÐÃâ·ÑµÄÎç²Í£¬Ê¹ÓÃË÷ÒýÊÇÐèÒª¸¶³ö´ú¼ÛµÄ
Ë÷ÒýµÄÓŵãÓÐÄ¿¹²¶Ã£¬µ«ÊÇ£¬È´ºÜÉÙÓÐÈ˹ØÐĹý²ÉÓÃË÷ÒýËùÐèÒª¸¶³öµÄ³É±¾¡£ÈôÊý¾Ý¿â¹ÜÀíÔ±Äܹ»¶ÔË÷ÒýËùÐèÒª¸¶³öµÄ´ú¼ÛÓÐÒ»¸ö³ä·ÖµÄÈÏʶ£¬Ò²¾Í²»»áÄÇôËæÒâµ½´¦½¨Á¢Ë÷ÒýÁË¡£
×ÐϸÊýÊý£¬Æäʵ½¨Á¢Ë÷ÒýµÄ´ú¼Û»¹ÊÇÂù´óµÄ¡£Èç´´½¨Ë÷ÒýºÍά»¤Ë÷Òý¶¼ÐèÒª»¨·Ñʱ¼äÓ뾫Á¦¡£ÌرðÊÇÔÚÊý¾Ý¿âÉè¼ÆµÄʱºò£¬Êý¾Ý¿â¹ÜÀíԱΪ±íÖеÄÄÄЩ×Ö¶ÎÐèÒª½¨Á¢Ë÷Òý£¬Òªµ÷ÑС¢ÒªÐµ÷¡£Èçµ±½¨ÓÐË÷ÒýµÄ±íÖеļͼÓÖÔö¼Ó¡¢É¾³ý¡¢Ð޸IJÙ×÷ʱ£¬Êý¾Ý¿âÒª¶ÔË÷Òý½øÐÐÖØе÷Õû¡£ËäÈ»Õâ¸ö¹¤×÷Êý¾Ý¿â×Ô¶¯»áÍê³É£¬µ«ÊÇ£¬ÐèÒªÏûºÄ·þÎñÆ÷µÄ×ÊÔ´¡£µ±±íÖеÄÊý¾ÝÔ½¶à£¬Õâ¸öÏûºÄµÄ×ÊÔ´Ò²¾ÍÔ½¶à¡£ÈçË÷ÒýÊÇÊý¾Ý¿âÖÐʵ¼Ê´æÔڵĶÔÏó£¬ËùÒÔ£¬Ã¿¸öË÷Òý¶¼»áÕ¼ÓÃÒ»¶¨µÄÎïÀí¿Õ¼ä¡£ÈôË÷Òý¶àÁË£¬²»µ«»áÕ¼ÓôóÁ¿µÄÎïÀí¿Õ¼ä£¬¶øÇÒ£¬Ò²»áÓ°Ïìµ½Õû¸öÊý¾Ý¿âµÄÔËÐÐÐÔÄÜ¡£
¿É¼û£¬Êý¾Ý¿â¹ÜÀíÔ±ÈôÒª²ÉÓÃË÷ÒýÀ´Ìá¸ßϵͳµÄÐÔÄÜ£¬×ÔÉíÈÔÈ»ÐèÒª¸¶³ö²»ÉٵĴú¼Û¡£Êý¾Ý¿â¹ÜÀíÔ±ÏÖÔÚÒª¿¼ÂǵľÍÊÇÈçºÎÔÚÕâÁ½¸öÖ®¼äÈ¡µÃÒ»¸ö¾ùºâ¡£»òÕß˵£¬ÕÒµ½Ò»¸ö»Ø±¨ÓëͶÈëµÄÁÙ½çµã¡£
ÌúÂɶþ£º¶ÔÓÚ²éѯÖкÜÉÙÉæ¼°µÄÁлòÕßÖظ´Öµ±È½Ï¶àµÄÁУ¬²»Òª½¨Á¢Ë÷Òý
ÔÚ²éѯµÄʱºò£¬Èç¹ûÎÒÃDz»°´Ä³¸ö×Ö¶ÎÈ¥²éѯ£¬ÔòÔÚÕâ¸ö×Ö¶ÎÉϽ¨Á¢Ë÷ÒýÒ²ÊÇÀË·Ñ¡£ÈçÏÖÔÚÓÐÒ»ÕÅÔ±¹¤ÐÅÏ¢±í£¬ÎÒÃÇ¿ÉÄÜ°´Ô±¹¤±àºÅ¡¢Ô±¹¤ÐÕÃû¡¢»òÕß³öÉíµØÈ¥²éѯԱ¹¤ÐÅÏ¢¡£µ«ÊÇ£¬ÎÒÃÇÍùÍù²»»á°´ÕÕÉí·ÝÖ¤ºÅÂëÈ¥²éѯ¡£ËäÈ»Õâ¸öÉí·ÝÖ¤ºÅÂëÊÇΨһµÄ¡£´Ëʱ£¬¼´Ê¹ÔÚÕâ¸ö×Ö¶ÎÉϽ¨Á¢Ë÷Òý£¬Ò²²»Äܹ»Ìá¸ß²éѯµÄËٶȡ£Ïà·´£¬Ôö¼ÓÁËϵͳά»¤Ê±¼äºÍÕ¼ÓÃÁËϵͳ¿Õ¼ä¡£Õâ¼òÖ±¾ÍÊÇ°áÆðʯͷÔÒ×Ô¼ºµÄ½Åѽ¡£
ÁíÍ⣬ÈçÉÏÃæµÄÔ±¹¤ÐÅÏ¢±í£¬ÓÐЩ×Ö¶ÎÖظ´Öµ±È½Ï¶à¡£ÈçÐÔ±ð×Ö¶ÎÖ÷Òª¾ÍÊÇ“ÄД¡¢“Å®”;ְλ×Ö¶ÎÖÐÒ²ÊÇÓÐÏ޵ļ¸¸öÄÚÈÝ¡£´Ëʱ£¬ÔÚÕâЩ×Ö¶ÎÉÏÌí¼ÓË÷ÒýÒ²²»»áÏÔÖøµÄÔö¼Ó²éѯËٶȣ¬¼õÉÙÓû§ÏìӦʱ¼ä¡£
Ïà¹ØÎĵµ£º
½ñÌìÓиöѧÉúÎÊÎÒµ÷ÓðüÀïÃæ¾ßÓÐÓαêÀàÐ͵ÄÊä³ö²ÎÊý£¬¿ÉÊÇÔÚÓÃPL/SQL³ÌÐòµ÷ÓõÄʱºò¾ÓÈ»±¨³ö²ÎÊý¸öÊý»òÀàÐÍ´íÎóµÄÒì³£ÐÅÏ¢£¬ÓÚÊÇ×Ô¼ºÒ²ÊÔÁËһϣ¬¹ûÈ»Êdzö´íÁË¡£È»ºó¾Í×Ô¼º×ÁÄ¥ÁËһϡ¢²é²é×ÊÁϺÍÎÊÎÊͬÊ£¬ÔÀ´ÎÊÌâÊǺܼòµ¥µÄ£¬ÏÈ¿´Ò»Ï³ÌÐòµÄ½á¹¹´úÂ룺
CREATE OR REPLACE PACKAGE Pkg_S ......
µ÷ÕûµÄÄ¿µÄ¾ÍÊÇΪÁËÏûºÄ×îСµÄ×ÊÔ´À´Íê³É¹¦ÄÜ£¬Í¨¹ý²é¿´Ö´Ðмƻ®ºÍ¸÷ÖÖͳ¼ÆÐÅÏ¢À´·Ö±æµ÷ÕûºóµÄsql¶Ô×ÊÔ´µÄºÄ·ÑÇé¿ö£¬À´ÕÒ³öÒ»¸ö³É±¾×îСµÄsqlÓï¾ä
¼ì²éϵͳµÄI/OÎÊÌâ
vmstateÄܼì²éÕû¸öϵͳµÄiostat£¨IO statistics£©
²é¿´¸ÃSQLµÄresponse time(db block gets/consistent gets/physical reads/sorts (disk)) ......
//°´×ÔÈ»ÖÜͳ¼Æ
select to_char(date,'iw'),sum()
from
where
group by to_char(date,'iw')
//°´×ÔÈ»ÔÂͳ¼Æ
select to_char(date,'mm'),sum()
from
where
group by to_char(date,'mm')
//°´¼¾Í³¼Æ
select to_char(date,'q'),sum()
fr ......
MSSQL»¹ÔÊý¾Ý¿âʧ°Ü£¬ÌáʾÈçÏ£º »¹Ô¶ÔÓë·þÎñÆ÷ ʧ°Ü¡£(Microsoft.SqlServer.Smo) ÆäËüÐÅÏ¢£º ©§ ©»¡úÖ´ÐÐTransact-SQLÓï¾ä»òÅú´¦Àíʱ·¢ÉúÒì³£¡££¨Microsoft.SqlServer.ConnectionsInfo£© ©§ ©»¡ú²»ÄÜÑ¡ÔñÎļþ»òÎļþ×é¡°¡¡¡±ÓÃÓڴ˲Ù×÷¡£ RESTORE DATABASE ÕýÔÚÒì³£ÖÕÖ¹¡££¨Microsoft SQL Server, ´íÎó£º3219£© ³öÏÖ´Ë ......
1. ¶¨ÒåÓα궨Òå
ÓαêÓï¾äµÄºËÐÄÊǶ¨ÒåÁËÒ»¸öÓαê±êʶÃû£¬²¢°ÑÓαê±êʶÃûºÍÒ»¸ö²éѯÓï¾ä¹ØÁªÆðÀ´¡£DECLAREÓï¾äÓÃÓÚÉùÃ÷Óα꣬Ëüͨ¹ýSELECT²éѯ¶¨ÒåÓαê´æ´¢µÄÊý¾Ý¼¯ºÏ¡£Óï¾ä¸ñʽΪ£º
DECLARE ÓαêÃû³Æ [INSENSITIVE] [SCROLL]
CURSOR FOR selectÓï¾ä
[FOR{READ ONLY|UPDATE[OF ÁÐÃû×Ö±í]}]
²ÎÊý˵Ã÷£º
INSENSITIVEÑ¡Ï ......