SQL ±íËø
ÆäʵÄã¿ÉÒÔʹÓÃÊÂÎñ´¦Àí
±È·½ËµÔÚÒ»¸ö×Ö¶ÎÀïÃæÌí¼ÓÒ»¸öboolean µÄ×ֶε±ÄãÒª´¦Àí¸Ã×ֶεÄʱºò¾Í True ÄÄô±ðµÄÈ˶¼²»¿ÉÒÔ½øÐвÙ×÷
¡¡Èç¹ûÊÇFalse ÄÄô¾Í¿ÉÒÔ½øÐвÙ×÷¡«¡«ºÇ¿É¡«¡«ÎÒÊÇÕâÑùµÄ
¡¡¡¡²»¹ýÄã¿ÉÒÔ¿´¿´¡¡
¡¡SQLËø»úÖÆ
¡¡¡¡ÒÔÏÂÊÇÎÒÕÒµÄһЩÁÏ¡¡Èç¹ûÒªÀí½âSQLËø»úÖÆ ×îºÃ°ÑÏÂÀ´¿´ÍêŶ
ĬÈϵÄÊÂÎñ¸ôÀ뼶±ðÏÂ:
Insert£¬update £¬deleteϵÄÊÇXËø, »áµÈ´ýÊÂÎñÍê³É
select ϵÄÊÇSËø, ²éѯÍê³É¼´ÊÍ·Å
ËøµÄ¸ÅÊö
Ò». ΪʲôҪÒýÈëËø
¶à¸öÓû§Í¬Ê±¶ÔÊý¾Ý¿âµÄ²¢·¢²Ù×÷ʱ»á´øÀ´ÒÔÏÂÊý¾Ý²»Ò»ÖµÄÎÊÌâ:
¶ªÊ§¸üÐÂ
A,BÁ½¸öÓû§¶ÁͬһÊý¾Ý²¢½øÐÐÐÞ¸Ä,ÆäÖÐÒ»¸öÓû§µÄÐ޸Ľá¹ûÆÆ»µÁËÁíÒ»¸öÐ޸ĵĽá¹û,±ÈÈ綩Ʊϵͳ
Ôà¶Á
AÓû§ÐÞ¸ÄÁËÊý¾Ý,ËæºóBÓû§ÓÖ¶Á³ö¸ÃÊý¾Ý,µ«AÓû§ÒòΪijЩÔÒòÈ¡ÏûÁ˶ÔÊý¾ÝµÄÐÞ¸Ä,Êý¾Ý»Ö¸´ÔÖµ,´ËʱBµÃµ½µÄÊý¾Ý¾ÍÓëÊý¾Ý¿âÄÚµÄÊý¾Ý²úÉúÁ˲»Ò»ÖÂ
²»¿ÉÖظ´¶Á
AÓû§¶ÁÈ¡Êý¾Ý,ËæºóBÓû§¶Á³ö¸ÃÊý¾Ý²¢ÐÞ¸Ä,´ËʱAÓû§ÔÙ¶ÁÈ¡Êý¾Ýʱ·¢ÏÖÇ°ºóÁ½´ÎµÄÖµ²»Ò»ÖÂ
²¢·¢¿ØÖƵÄÖ÷Òª·½·¨ÊÇ·âËø,Ëø¾ÍÊÇÔÚÒ»¶Îʱ¼äÄÚ½ûÖ¹Óû§×öijЩ²Ù×÷ÒÔ±ÜÃâ²úÉúÊý¾Ý²»Ò»ÖÂ
¶þ ËøµÄ·ÖÀà
ËøµÄÀà±ðÓÐÁ½ÖÖ·Ö·¨£º
1. ´ÓÊý¾Ý¿âϵͳµÄ½Ç¶ÈÀ´¿´£º·ÖΪ¶ÀÕ¼Ëø£¨¼´ÅÅËüËø£©£¬¹²ÏíËøºÍ¸üÐÂËø
MS-SQL Server ʹÓÃÒÔÏÂ×ÊÔ´Ëøģʽ¡£
Ëøģʽ ÃèÊö
¹²Ïí (S) ÓÃÓÚ²»¸ü¸Ä»ò²»¸üÐÂÊý¾ÝµÄ²Ù×÷£¨Ö»¶Á²Ù×÷£©£¬Èç SELECT Óï¾ä¡£
¸üР(U) ÓÃÓڿɸüеÄ×ÊÔ´ÖС£·ÀÖ¹µ±¶à¸ö»á»°ÔÚ¶ÁÈ¡¡¢Ëø¶¨ÒÔ¼°Ëæºó¿ÉÄܽøÐеÄ×ÊÔ´¸üÐÂʱ·¢Éú³£¼ûÐÎʽµÄËÀËø¡£
ÅÅËü (X) ÓÃÓÚÊý¾ÝÐ޸IJÙ×÷£¬ÀýÈç INSERT¡¢UPDATE »ò DELETE¡£È·±£²»»áͬʱͬһ×ÊÔ´½øÐжàÖظüС£
ÒâÏòËø ÓÃÓÚ½¨Á¢ËøµÄ²ã´Î½á¹¹¡£ÒâÏòËøµÄÀàÐÍΪ£ºÒâÏò¹²Ïí (IS)¡¢ÒâÏòÅÅËü (IX) ÒÔ¼°ÓëÒâÏòÅÅËü¹²Ïí (SIX)¡£
¼Ü¹¹Ëø ÔÚÖ´ÐÐÒÀÀµÓÚ±í¼Ü¹¹µÄ²Ù×÷ʱʹÓ᣼ܹ¹ËøµÄÀàÐÍΪ£º¼Ü¹¹ÐÞ¸Ä (Sch-M) ºÍ¼Ü¹¹Îȶ¨ÐÔ (Sch-S)¡£
´óÈÝÁ¿¸üР(BU) Ïò±íÖдóÈÝÁ¿¸´ÖÆÊý¾Ý²¢Ö¸¶¨ÁË TABLOCK ÌáʾʱʹÓá£
¹²ÏíËø
¹²Ïí (S) ËøÔÊÐí²¢·¢ÊÂÎñ¶ÁÈ¡ (SELECT) Ò»¸ö×ÊÔ´¡£×ÊÔ´ÉÏ´æÔÚ¹²Ïí (S) Ëøʱ£¬ÈκÎÆäËüÊÂÎñ¶¼²»ÄÜÐÞ¸ÄÊý¾Ý¡£Ò»µ©ÒѾ¶ÁÈ¡Êý¾Ý£¬±ãÁ¢¼´ÊÍ·Å×ÊÔ´ÉϵĹ²Ïí (S) Ëø£¬³ý·Ç½«ÊÂÎñ¸ôÀ뼶±ðÉèÖÃΪ¿ÉÖظ´¶Á»ò¸ü¸ß¼¶±ð£¬»òÕßÔÚÊÂÎñÉú´æÖÜÆÚÄÚÓÃËø¶¨Ìáʾ±£Áô¹²Ïí (S) Ëø¡£
¸üÐÂËø
¸üР(U) Ëø¿ÉÒÔ·Àֹͨ³£ÐÎʽµÄËÀËø¡£Ò»°ã¸üÐÂģʽÓÉÒ»¸öÊÂÎñ×é³É£¬´ËÊÂÎñ¶ÁÈ¡¼Ç¼£¬»ñÈ¡×ÊÔ´£¨Ò³»òÐУ©µÄ¹²Ïí (S) Ëø£¬È»ºóÐÞ¸ÄÐУ¬´Ë²Ù×÷ÒªÇ
Ïà¹ØÎĵµ£º
--¼ì²âCPUѹÁ¦µÄÒ»¸ö·½·¨ÊǼÆËãÔËÐÐ״̬ÏµĹ¤×÷½ø³ÌÊýÁ¿£¬
--ͨ¹ýÖ´ÐÐÈçϵÄDMV²éѯ¿ÉÒԵõ½Õâ¸öÐÅÏ¢
SELECT COUNT(*) AS workers_waiting_for_cpu,t2.scheduler_id
from sys.dm_os_workers AS t1, sys.dm_os_schedulers AS t2
WHERE t1.state='RUNNABLE' AND
t1.scheduler_address = t2.scheduler_address A ......
DBCC memorystatus
--²éѯ»º³åÇø³ØÏûºÄµÄÄÚ´æ×ÜÁ¿°üÀ¨AWE
SELECT
SUM(multi_pages_kb+virtual_memory_committed_kb+shared_memory_committed_kb+
awe_allocated_kb) AS [Used by BPool, kb]
from sys.dm_os_memory_clerks WHERE type='MEMORYCLERK_SQLBUFFERPOOL'
&nb ......
sql serverÊý¾ÝÀàÐÍcharºÍnchar,varcharºÍnvarchar,textºÍntextÔÊÐíµÄ×Ö·û³¤¶È
×Ö·û´®
char
¹Ì¶¨³¤¶ÈµÄ·Ç Unicode ×Ö·ûÊý¾Ý£¬×î´ó³¤¶ÈΪ 8,000 ¸ö×Ö·û¡£
varchar
¿É±ä³¤¶ÈµÄ·Ç Unicode Êý¾Ý£¬×Ϊ 8,000 ¸ö×Ö·û¡£
text
¿É±ä³¤¶ÈµÄ·Ç Unicode Êý¾Ý£¬×î´ó³¤¶ÈΪ 2^31 - 1 (2,147,483,647) ¸ö×Ö·û¡£
Unicode ×Ö·û´®
......
¹þÏ£Áª½ÓÊǵÚÈýÖÖÎïÀíÁª½ÓÔËËã·û£¬µ±Ëµµ½¹þÏ£Áª½Óʱ£¬ËüÊÇÈýÖÖÁª½ÓÔËËãÖÐÐÔÄÜ×îºÃµÄ£®Ç¶Ì×Ñ»·Áª½ÓÊÊÓÃÓÚÏà¶Ô½ÏСµÄÊý¾Ý¼¯£¬¶øºÏ²¢Áª½ÓÊÊÓÃÓÚÖеȹæÄ£µÄÊý¾Ý¼¯£¬¶ø¹þÏ£Áª½ÓÔòÊÊÓÃÓÚ´ó¹æÄ£Áª½ÓµÄÊý¾Ý¼¯£®
¹þÏ£Áª½ÓËã·¨²ÉÓ㢹¹½¨£¢ºÍ£¢Ì½²â£¢Á½²½À´Ö´ÐУ®ÔÚ£¢¹¹½¨£¢½×¶Î£¬ËüÊ×ÏÈ´ÓµÚÒ»¸öÊäÈëÖжÁÈ¡ËùÓÐÐУ¨³£½Ð×ö×ó»ò¹¹½¨Ê ......