Ëø³õ̽(sqlserver 2005)
HOLDLOCK ½«¹²ÏíËø±£Áôµ½ÊÂÎñÍê³É£¬¶ø²»ÊÇÔÚÏàÓ¦µÄ±í¡¢ÐлòÊý¾ÝÒ³²»ÔÙÐèҪʱ¾ÍÁ¢¼´ÊÍ·ÅËø¡£HOLDLOCK µÈͬÓÚ SERIALIZABLE¡£
NOLOCK ²»Òª·¢³ö¹²ÏíËø£¬²¢ÇÒ²»ÒªÌṩÅÅËüËø¡£µ±´ËÑ¡ÏîÉúЧʱ£¬¿ÉÄÜ»á¶ÁȡδÌá½»µÄÊÂÎñ»òÒ»×éÔÚ¶ÁÈ¡Öмä»Ø¹öµÄÒ³Ãæ¡£ÓпÉÄÜ·¢ÉúÔà¶Á¡£½öÓ¦ÓÃÓÚ SELECT Óï¾ä¡£
PAGLOCK ÔÚͨ³£Ê¹Óõ¥¸ö±íËøµÄµØ·½²ÉÓÃÒ³Ëø¡£
READCOMMITTED ÓÃÓëÔËÐÐÔÚÌá½»¶Á¸ôÀ뼶±ðµÄÊÂÎñÏàͬµÄËøÓïÒåÖ´ÐÐɨÃ衣ĬÈÏÇé¿öÏ£¬SQL Server 2000 Ôڴ˸ôÀ뼶±ðÉϲÙ×÷¡£ READPAST Ìø¹ýËø¶¨ÐС£´ËÑ¡Ïîµ¼ÖÂÊÂÎñÌø¹ýÓÉÆäËüÊÂÎñËø¶¨µÄÐУ¨ÕâЩÐÐƽ³£»áÏÔʾÔÚ½á¹û¼¯ÄÚ£©£¬¶ø²»ÊÇ×èÈû¸ÃÊÂÎñ£¬Ê¹ÆäµÈ´ýÆäËüÊÂÎñÊÍ·ÅÔÚÕâЩÐÐÉϵÄËø¡£READPAST ËøÌáʾ½öÊÊÓÃÓÚÔËÐÐÔÚÌá½»¶Á¸ôÀ뼶±ðµÄÊÂÎñ£¬²¢ÇÒÖ»ÔÚÐм¶ËøÖ®ºó¶ÁÈ¡¡£½öÊÊÓÃÓÚ SELECT Óï¾ä¡£ READUNCOMMITTED µÈͬÓÚ NOLOCK¡£
REPEATABLEREAD ÓÃÓëÔËÐÐÔÚ¿ÉÖظ´¶Á¸ôÀ뼶±ðµÄÊÂÎñÏàͬµÄËøÓïÒåÖ´ÐÐɨÃè¡£
ROWLOCK ʹÓÃÐм¶Ëø£¬¶ø²»Ê¹ÓÃÁ£¶È¸ü´ÖµÄÒ³¼¶ËøºÍ±í¼¶Ëø¡£
SERIALIZABLE ÓÃÓëÔËÐÐÔÚ¿É´®ÐжÁ¸ôÀ뼶±ðµÄÊÂÎñÏàͬµÄËøÓïÒåÖ´ÐÐɨÃè¡£µÈͬÓÚ HOLDLOCK¡£
TABLOCK ʹÓñíËø´úÌæÁ£¶È¸üϸµÄÐм¶Ëø»òÒ³¼¶Ëø¡£ÔÚÓï¾ä½áÊøÇ°£¬SQL Server Ò»Ö±³ÖÓиÃËø¡£µ«ÊÇ£¬Èç¹ûͬʱָ¶¨ HOLDLOCK£¬ÄÇôÔÚÊÂÎñ½áÊø֮ǰ£¬Ëø½«±»Ò»Ö±³ÖÓС£ TABLOCKX ʹÓñíµÄÅÅËüËø¡£¸ÃËø¿ÉÒÔ·ÀÖ¹ÆäËüÊÂÎñ¶ÁÈ¡»ò¸üÐÂ±í£¬²¢ÔÚÓï¾ä»òÊÂÎñ½áÊøÇ°Ò»Ö±³ÖÓС£
UPDLOCK ¶ÁÈ¡±íʱʹÓøüÐÂËø£¬¶ø²»Ê¹Óù²ÏíËø£¬²¢½«ËøÒ»Ö±±£Áôµ½Óï¾ä»òÊÂÎñµÄ½áÊø¡£UPDLOCK µÄÓŵãÊÇÔÊÐíÄú¶ÁÈ¡Êý¾Ý£¨²»×èÈûÆäËüÊÂÎñ£©²¢ÔÚÒÔºó¸üÐÂÊý¾Ý£¬Í¬Ê±È·±£×Ô´ÓÉϴζÁÈ¡Êý¾ÝºóÊý¾ÝûÓб»¸ü¸Ä¡£
XLOCK ʹÓÃÅÅËüËø²¢Ò»Ö±±£³Öµ½ÓÉÓï¾ä´¦ÀíµÄËùÓÐÊý¾ÝÉϵÄÊÂÎñ½áÊøʱ¡£
¿ÉÒÔʹÓà PAGLOCK »ò TABLOCK Ö¸¶¨¸ÃËø£¬ÕâÖÖÇé¿öÏÂÅÅËüËøÊÊÓÃÓÚÊʵ±¼¶±ðµÄÁ£¶ÈËøµÄ¸ÅÊö
Ò». ΪʲôҪÒýÈëËø
¶à¸öÓû§Í¬Ê±¶ÔÊý¾Ý¿âµÄ²¢·¢²Ù×÷ʱ»á´øÀ´ÒÔÏÂÊý¾Ý²»Ò»ÖµÄÎÊÌâ: ¶ªÊ§¸üÐÂ
A,BÁ½¸öÓû§¶ÁͬһÊý¾Ý²¢½øÐÐÐÞ¸Ä,ÆäÖÐÒ»¸öÓû§µÄÐ޸Ľá¹ûÆÆ»µÁËÁíÒ»¸öÐ޸ĵĽá¹û,±ÈÈ綩Ʊϵͳ
Ôà¶Á
AÓû§ÐÞ¸ÄÁËÊý¾Ý,ËæºóBÓû§ÓÖ¶Á³ö¸ÃÊý¾Ý,µ«AÓû§ÒòΪijЩÔÒòÈ¡ÏûÁ˶ÔÊý¾ÝµÄÐÞ¸Ä,Êý¾Ý»Ö¸´ÔÖµ,´ËʱBµÃµ½µÄÊý¾Ý¾ÍÓëÊý¾Ý¿âÄÚµÄÊý¾Ý²úÉúÁ˲»Ò»ÖÂ
²»¿ÉÖظ´¶Á
AÓû§¶ÁÈ¡Êý¾Ý,ËæºóBÓû§¶Á³ö¸ÃÊý¾Ý²¢ÐÞ¸
Ïà¹ØÎĵµ£º
±¾ÆªÄÚÈÝϵÊôSQLServer¸ß¼¶±à³Ì£¬ÊÊÓÃÓÚÓûÌá¸ß×Ô¼ººÍ¸´Ï°»òÓ¦¸¶ÃæÊÔµÄÅóÓÑÔĶÁ£¬Í¬Ê±±¾ÈËѧϰ²»¾Ã£¬ÔÚ×ܽáºÍ¹éÄÉʱ´íÎóºÍ²»Ç¡µ±Ö®´¦ÔÚËùÄÑÃ⣬»¹ÇëÖ¸³öÆäÖБ¶ËÄß’£¬ÓèÒÔÍêÉÆ¡£
±í1:Users
USE [Wish]
GO
/****** ¶ÔÏó: Table [dbo].[Users] ½Å±¾ÈÕÆÚ: ......
ÔÚSQL Server ÖвåÈëÒ»ÌõÊý¾ÝʹÓÃInsertÓï¾ä£¬µ«ÊÇÈç¹ûÏëÒªÅúÁ¿²åÈëÒ»¶ÑÊý¾ÝµÄ»°£¬Ñ»·Ê¹ÓÃInsert²»½öЧÂʵͣ¬¶øÇһᵼÖÂSQLһϵͳÐÔÄÜÎÊÌâ¡£ÏÂÃæ½éÉÜSQL ServerÖ§³ÖµÄÁ½ÖÖÅúÁ¿Êý¾Ý²åÈë·½·¨£ºBulkºÍ±íÖµ²ÎÊý(Table-Valued Parameters)¡£
ÔËÐÐÏÂÃæµÄ½Å±¾£¬½¨Á¢²âÊÔÊý¾Ý¿âºÍ±íÖµ²ÎÊý¡£
´úÂëÈçÏÂ:
--Create D ......
select
convert(char(4),auth,120)+'Äê'+
substring(convert(char(10),auth,120),6,2)+'ÔÂ'+
substring(convert(char(10),auth,120),9,2)+'ÈÕ',
convert(char(4),appr,120)+'Äê'+
substring(convert(char(10),appr,120),6,2)+'ÔÂ'+
substring(convert(char(10),appr,120),9,2)+'ÈÕ'
from a
ÒÔÉÏ´úÂëʵÏֵĹ¦Ä ......
SQL Server 2005Êý¾Ý¿â±¸·ÝºÍ»Ö¸´ÌØÐÔ
SQL Server 2000ÖдæÔÚµÄÐí¶àµÄ±¸·ÝºÍ»Ö¸´ÌØÐÔ¶¼Í¬Ñù±£ÁôÔÚÁËSQL Server 2005ÖУ¬µ«ÊÇÓÐһЩеÄÌá¸ßͬÑùÖµµÃÎÒÃǹØ×¢¡£
¾µÏñ±¸·Ý
SQL Server 2005ÈÃÄã¿ÉÒÔ´´½¨¾µÏñ±¸·Ý¡£¾µÏñ±¸·ÝÔÊÐíÄãΪ±¸·ÝÎļþ´´½¨Á½¸ö»òÕßËĸöͬÑùµÄ¿½±´£¬ÒÔ·À±¸ÆäÖеÄijһ¸ö¼¯ºÏË𻵵ÄÇé¿ö¡£¾µÏñ¾ßÓ ......