SQL SERVERÈçºÎ¼õÉÙËÀËø
Ö÷ÒªÕë¶ÔSQL ServerÊý¾Ý¿âËÀËøÏÖÏóµÄÔ¤·À¼°½â¾ö´ëÊ©½øÐÐÁËÏêϸµÄ½éÉÜ£¬¸ü¶àÄÚÈÝÇë´ó¼Ò²Î¿¼ÏÂÎÄ£º
¡¡¡¡ËÀËøÊÇÖ¸ÔÚij×é×ÊÔ´ÖУ¬Á½¸ö»òÁ½¸öÒÔÉϵÄÏß³ÌÔÚÖ´Ðйý³ÌÖУ¬ÔÚÕù¶áijһ×ÊԴʱ¶øÔì³É»¥ÏàµÈ´ýµÄÏÖÏó£¬ÈôÎÞÍâÁ¦µÄ×÷ÓÃÏÂ,ËüÃǶ¼½«ÎÞ·¨ÍƽøÏÂÈ¥£¬ËÀʱ¾Í¿ÉÄÜ»á²úÉúËÀËø,ÕâЩÓÀÔ¶ÔÚ»¥ÏàµÈ´ýµÄ½ø³Ì³ÆΪËÀËøÏ̡߳£¼òµ¥µÄ˵£¬½ø³ÌAµÈ´ý½ø³ÌBÊÍ·ÅËûµÄ×ÊÔ´£¬BÓֵȴýAÊÍ·ÅËûµÄ×ÊÔ´£¬ÕâÑù»¥ÏàµÈ´ý¾ÍÐγÉËÀËø¡£
¡¡¡¡ÈçÔÚÊý¾Ý¿âÖУ¬Èç¹ûÐèÒª¶ÔÒ»ÌõÊý¾Ý½øÐÐÐ޸ģ¬Ê×ÏÈÊý¾Ý¿â¹ÜÀíϵͳ»áÔÚÉÏÃæ¼ÓËø£¬ÒÔ±£Ö¤ÔÚͬһʱ¼äÖ»ÓÐÒ»¸öÊÂÎñÄܽøÐÐÐ޸IJÙ×÷¡£ÈçÊÂÎñ1µÄÏß³Ì T1¾ßÓбíAÉϵÄÅÅËüËø£¬ÊÂÎñ2µÄÏß³ÌT2 ¾ßÓбíBÉϵÄÅÅËüËø£¬²¢ÇÒÖ®ºóÐèÒª±íAÉϵÄËø¡£ÊÂÎñ2ÎÞ·¨»ñµÃÕâÒ»Ëø£¬ÒòΪÊÂÎñ1ÒÑÓµÓÐËü¡£ÊÂÎñ2±»×èÈû£¬µÈ´ýÊÂÎñ1¡£È»ºó£¬ÊÂÎñ1ÐèÒª±íBµÄËø£¬µ«ÎÞ·¨»ñµÃËø£¬ÒòΪÊÂÎñ2½«ËüËø¶¨ÁË¡£ÊÂÎñÔÚÌá½»»ò»Ø¹ö֮ǰ²»ÄÜÊͷųÖÓеÄËø¡£ÒòΪÊÂÎñÐèÒª¶Ô·½¿ØÖƵÄËø²ÅÄܼÌÐø²Ù×÷£¬ËùÒÔËüÃDz»ÄÜÌá½»»ò»Ø¹ö£¬ÕâÑùÊý¾Ý¿â¾Í»á·¢ÉúËÀËøÁË¡£
¡¡¡¡ÈçÔÚ±àд´æ´¢¹ý³ÌµÄʱºò£¬ÓÉÓÚÓÐЩ´æ´¢¹ý³ÌÊÂÎñÐԵIJÙ×÷±È½ÏƵ·±£¬Èç¹ûÏÈËøס±íA£¬ÔÙËøס±íB£¬ÄÇôÔÚËùÓеĴ洢¹ý³ÌÖж¼Òª°´ÕÕÕâ¸ö˳ÐòÀ´Ëø¶¨ËüÃÇ¡£Èç¹ûÎÞÒâÖÐij¸ö´æ´¢¹ý³ÌÖÐÏÈËø¶¨±íB£¬ÔÙËø¶¨±íA£¬Õâ¿ÉÄܾͻᵼÖÂÒ»¸öËÀËø¡£¶øÇÒËÀËøÒ»°ãÊDz»Ì«ÈÝÒ×±»·¢Ïֵġ£
¡¡¡¡Èç¹û·þÎñÆ÷ÉϾ³£³öÏÖÕâÖÖËÀËøÇé¿ö£¬¾Í»á½µµÍ·þÎñÆ÷µÄÐÔÄÜ£¬ËùÒÔÓ¦ÓóÌÐòÔÚʹÓõÄʱºò£¬ÎÒÃǾÍÐèÒª¶ÔÆä½øÐиú×Ù£¬Ê¹ÓÃsp_whoºÍsp_who2À´È·¶¨¿ÉÄÜÊÇÄÄЩÓû§×èÈûÁËÆäËûÓû§£¬ÎÒÃÇ»¹¿ÉÒÔÓÃÏÂÃæµÄ´æ´¢¹ý³ÌÀ´¸ú×Ù¾ßÌåµÄËÀËøÖ´ÐеÄÓ°Ï죺
¡¡¡¡
¡¡¡¡create procedure sp_who_lock
¡¡¡¡as
¡¡¡¡begin
¡¡¡¡declare @spid int,@bl int,
¡¡¡¡@intTransactionCountOnEntry int,
¡¡¡¡@intRowcount int,
¡¡¡¡@intCountProperties int,
¡¡¡¡@intCounter int
¡¡¡¡create table #tmp_lock_who (id int identity(1,1),spid smallint,bl smallint)
¡¡¡¡IF @@ERROR<>0 RETURN @@ERROR
¡¡¡¡insert into #tmp_lock_who(spid,bl) select 0 ,blocked
¡¡¡¡ from (select * from sysprocesses where blocked>0 ) a
¡¡¡¡ where not exists(select * from (select * from sysprocesses where blocked>0 ) b
¡¡¡¡ where a.blocked=spid)
¡¡¡¡ union select spid,blocked from sysprocesses where blocked>0
¡¡¡¡IF @@ERROR<>0 RETURN @@ERROR
¡¡¡¡
¡¡¡¡
Ïà¹ØÎĵµ£º
ÎÄÕÂÀ´Ô´£ºHttp://www.simple-talk.com
ÔÎĵØÖ·£ºhttp://www.simple-talk.com/sql/learn-sql-server/managing-transaction-logs-in-sql-server/
Ô×÷ÕߣºRobert Sheldon
·Ò룺Èý½úÒ»Ö¦»¨
ÒëÎÄÔµØÖ·£ºhttp://prj.souty.cn/Admin/Knowledges/ShowKnowledge.aspx?id=44dbde74-d2c5-41a5-a8e9-375ba7103025
ÔÚ SQL Serv ......
Ò». ²éÕÒÖظ´¼Ç¼
1. ²éÕÒÈ«²¿Öظ´¼Ç¼
Select * from ±í Where Öظ´×ֶΠIn (Select Öظ´×Ö¶Î
from ±í Group By Öظ´×ֶΠHaving Count(*)>1)
2. ¹ýÂËÖظ´¼Ç¼(Ö»ÏÔʾһÌõ)
Select * from HZT Where ID In (Select Max(ID) from HZT Group By Title)
×¢£º´Ë´¦ÏÔʾID×î´óÒ»Ìõ¼Ç¼
¶þ. ɾ³ýÖظ´¼Ç ......
ת×Ô£ºhttp://jianghaifeng.blogchina.com/3841741.html
SQL½á¹¹»¯²éѯ×Ö·û´®µÄ¸Äд£¬ÊÇʵÏÖÊý¾Ý¿â²éѯÐÔÄÜÌáÉýµÄ×îÏÖʵ¡¢×îÓÐЧµÄÊֶΣ¬ÓÐʱÉõÖÁÊÇΨһµÄÊֶΣ¬±ÈÈçÔÚ²»ÔÊÐí´ó·ù¶ÈÐÞ¸ÄÏÖÓÐÊý¾Ý¿â½á¹¹µÄÇé¿öÏ¡£
ͨ¹ýÓÅ»¯SQLÓï¾äÌá¸ß²éѯÐÔÄܵĹؼüÊÇ£º
¸ù¾Ýʵ¼ÊÐèÇóÇé¿ö£¬½¨Á¢ºÏÊʵÄË÷Òý£»
......
·µ»Ø Variant (Long) µÄÖµ£¬±íʾÁ½¸öÖ¸¶¨ÈÕÆÚ¼äµÄʱ¼ä¼ä¸ôÊýÄ¿¡£
¡¡¡¡Óï·¨
¡¡¡¡DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
¡¡¡¡DateDiff º¯ÊýÓï·¨ÖÐÓÐÏÂÁÐÃüÃû²ÎÊý£º
¡¡¡¡²¿·Ö ÃèÊö
¡¡¡¡interval ±ØÒª¡£×Ö·û´®±í´ïʽ£¬±íʾÓÃÀ´¼ÆËãdate1 ºÍ date2 µÄʱ¼ä²îµÄʱ¼ä¼ä¸ô
¡¡¡¡Date1 ......