SQL ServerËÀËø×ܽá
1.
ËÀËøÔÀí
¸ù¾Ý²Ù×÷ϵͳÖеĶ¨Ò壺ËÀËøÊÇÖ¸ÔÚÒ»×é½ø³ÌÖеĸ÷¸ö½ø³Ì¾ùÕ¼Óв»»áÊͷŵÄ×ÊÔ´£¬µ«Òò»¥ÏàÉêÇë±»ÆäËû½ø³ÌËùÕ¾Óò»»áÊͷŵÄ×ÊÔ´¶ø´¦ÓÚµÄÒ»ÖÖÓÀ¾ÃµÈ´ý״̬¡£
ËÀËøµÄËĸö±ØÒªÌõ¼þ£º
»¥³âÌõ¼þ
(Mutual exclusion)
£º×ÊÔ´²»Äܱ»¹²Ïí£¬Ö»ÄÜÓÉÒ»¸ö½ø³ÌʹÓá£
ÇëÇóÓë±£³ÖÌõ¼þ
(Hold and wait)
£ºÒѾµÃµ½×ÊÔ´µÄ½ø³Ì¿ÉÒÔÔÙ´ÎÉêÇëеÄ×ÊÔ´¡£
·Ç°þ¶áÌõ¼þ
(No pre-emption)
£ºÒѾ·ÖÅäµÄ×ÊÔ´²»ÄÜ´ÓÏàÓ¦µÄ½ø³ÌÖб»Ç¿ÖƵذþ¶á¡£
Ñ»·µÈ´ýÌõ¼þ
(Circular wait)
£ºÏµÍ³ÖÐÈô¸É½ø³Ì×é³É»·Â·£¬¸Ã»·Â·ÖÐÿ¸ö½ø³Ì¶¼ÔڵȴýÏàÁÚ½ø³ÌÕýÕ¼ÓõÄ×ÊÔ´¡£
¶ÔÓ¦µ½
SQL Server
ÖУ¬µ±ÔÚÁ½¸ö»ò¶à¸öÈÎÎñÖУ¬Èç¹ûÿ¸öÈÎÎñËø¶¨ÁËÆäËûÈÎÎñÊÔͼËø¶¨µÄ×ÊÔ´£¬´Ëʱ»áÔì³ÉÕâЩÈÎÎñÓÀ¾Ã×èÈû£¬´Ó¶ø³öÏÖËÀËø£»ÕâЩ×ÊÔ´¿ÉÄÜÊÇ£ºµ¥ÐÐ
(RID
£¬¶ÑÖеĵ¥ÐÐ
)
¡¢Ë÷ÒýÖеļü
(KEY
£¬ÐÐËø
)
¡¢Ò³
(PAG
£¬
8KB)
¡¢Çø½á¹¹
(EXT
£¬Á¬ÐøµÄ
8
Ò³
)
¡¢¶Ñ»ò
B
Ê÷
(HOBT)
¡¢±í
(TAB
£¬°üÀ¨Êý¾ÝºÍË÷Òý
)
¡¢Îļþ
(File
£¬Êý¾Ý¿âÎļþ
)
¡¢Ó¦ÓóÌÐòרÓÃ×ÊÔ´
(APP)
¡¢ÔªÊý¾Ý
(METADATA)
¡¢·ÖÅäµ¥Ôª
(Allocation_Unit)
¡¢Õû¸öÊý¾Ý¿â
(DB)
¡£
Ò»¸öËÀËøʾÀýÈçÏÂͼËùʾ£º
˵Ã÷£º
T1
¡¢
T2
±íʾÁ½¸öÈÎÎñ£»
R1
ºÍ
R2
±íʾÁ½¸ö×ÊÔ´£»ÓÉ×ÊÔ´Ö¸ÏòÈÎÎñµÄ¼ýÍ·
(
Èç
R1->T1
£¬
R2->T2)
±íʾ¸Ã×ÊÔ´±»¸ÄÈÎÎñËù³ÖÓУ»ÓÉÈÎÎñÖ¸Ïò×ÊÔ´µÄ¼ýÍ·
(
Èç
T1->S2
£¬
T2->S1)
±íʾ¸ÃÈÎÎñÕýÔÚÇëÇó¶ÔӦĿ±ê×ÊÔ´£»
ÆäÂú×ãÉÏÃæËÀËøµÄËĸö±ØÒªÌõ¼þ£º
(1).
»¥³â£º×ÊÔ´
S1
ºÍ
S2
²»Äܱ»¹²Ïí£¬Í¬Ò»Ê±¼äÖ»ÄÜÓÉÒ»¸öÈÎÎñʹÓã»
(2).
ÇëÇóÓë±£³ÖÌõ¼þ£º
T1
³ÖÓÐ
S1
µÄͬʱ£¬ÇëÇó
S2
£»
T2
³ÖÓÐ
S2
µÄͬʱÇëÇó
S1
£»
(3).
·Ç°þ¶áÌõ¼þ£º
T1
ÎÞ·¨´Ó
T2
ÉÏ°þ¶á
S2
£¬
T2
Ò²ÎÞ·¨´Ó
T1
ÉÏ°þ¶á
S1
£»
(4).
Ñ»·µÈ´ýÌõ¼þ£ºÉÏͼÖеļýÍ·¹¹³É»·Â·£¬´æÔÚÑ»·µÈ´ý¡£
2.
ËÀËøÅŲé
(1).
ʹÓÃ
SQL Server
µÄϵͳ´æ´¢¹ý³Ì
sp_who
ºÍ
sp_lock
£¬¿ÉÒԲ鿴µ±Ç°Êý¾Ý¿âÖеÄËøÇé¿ö£»½ø¶ø¸ù¾Ý
objectID(@objID)(SQL Server 2005)/ object_name(@objID)(Sql Server 2000)
¿ÉÒԲ鿴Äĸö×ÊÔ´±»Ëø£¬ÓÃ
dbcc ld(@blk)
£¬¿ÉÒԲ鿴×îºóÒ»Ìõ·¢Éú¸ø
SQL Server
µÄ
Sql
Óï¾ä£»
CREATE
Table
#Who(spid&nbs
Ïà¹ØÎĵµ£º
ת×Ôhttp://lavasoft.blog.51cto.com/62575/23373
SQLÓïÑÔµÄCASEÓï¾ä±¸Íü
¸ÅÊö£º
SQLÓï¾äÖеÄCASEÓï¾äÓë¸ß¼¶ÓïÑÔÖеÄswitchÓï¾ä£¬ÊDZê×¼SQLµÄÓï·¨£¬ÊÊÓÃÓëÒ»¸öÌõ¼þÅжÏÓжàÖÖÖµµÄÇé¿öÏ·ֱðÖ´Ðв»Í¬µÄ²Ù×÷¡£Áé»îÓ¦ÓÃCASEÓï¾ä¿ÉÒÔʹSQLÓï¾ä±äµÃ¼ò½àÒ׶Á£¬ÏÂÃæÔÚDB2»·¾³ÏÂͨ¹ýÒ»¸ö¼òµ¥µÄ²éѯÀ´Õ¹Ê¾SQL CASEÓ ......
×î½üѧϰ linq to sql ¸Ð¾õ»¹ÊÇ¿ÉÒԵģ¬·½±ã¿ì½Ý£¬ÒÔÇ°ÎÊÊÇÒÔΪ²»ºÃÓ㬲»ÏëÓ㬵«ÊǽñÌìÓÃÁËһϸоõ»¹ÊDz»´íµÄ£¬ ȷʵÊǿ죬µ«ÊÇÎÒÓÖÔÚÏë
Èç¹û³ö´íÁËÔõô°ì£¬ÕâÑùÒ»¸öÀàÀï·ÅÄÇô¶àµÄÎļþÊÇÓе㲻ºÃ£¬ÔÙ˵ÁË linq to sql µÍ²ã²»ÖªµÀÔõôʵÏֵģ¬»¹ÊÇûÓÐ×Ô¼ºÐ´µÄ·ÃÎʸоõÊæ·þµãºÇºÇ£¡£¡£¡
Èç¹ûÊÇ¿ìËÙ¿ª·¢ÓÃ&nb ......
µÚÒ»µã£º
ʹÓÃÊÓͼ£¬¿ÉÒÔ¶¨ÖÆÓû§Êý¾Ý£¬¾Û½¹Ìض¨µÄÊý¾Ý¡£
½âÊÍ£º
ÔÚʵ¼Ê¹ý³ÌÖУ¬¹«Ë¾Óв»Í¬½ÇÉ«µÄ¹¤×÷ÈËÔ±£¬ÎÒÃÇÒÔÏúÊÛ¹«Ë¾ÎªÀýµÄ»°£¬
²É¹ºÈËÔ±£¬¿ÉÒÔÐèҪһЩÓëÆäÓйصÄÊý¾Ý£¬¶øÓëËûÎ޹صÄÊý¾Ý£¬¶ÔËûû
ÓÐÈκÎÒâÒ壬ÎÒÃÇ¿ÉÒÔ¸ù¾ÝÕâһʵ¼ÊÇé¿ö£¬×¨ÃÅΪ²É¹ºÈËÔ±´´½¨Ò»¸öÊÓ
ͼ£¬ÒÔºóËûÔÚ²éѯÊý¾Ýʱ£¬Ö»Ðèse ......
½ñÌìдÍøÕ¾µÄʱºòºÜ囧°¡£¬·¢ÏÖ²éÕÒÓû§È¨ÏÞµÄʱºòÎÞÔµÎ޹ʵÄͬһ¸öȨÏÞÖظ´³öÏֺܶà´Î
Ð޸ĺóµÄSQLÓï¾äÈçÏÂ
SELECT
node
.
id
,
node
.
name
,
access
.
role_id
from
think_role_user
AS
user
,
think_access
AS
access
,
think_node
AS
node
WHERE
user
.
user_id
=
......
create PROCEDURE [dbo].[AllDnn_NewsPublish_DeleteArticleByArticle]
@ArticleID nvarchar(200)
AS
declare @sql nvarchar(1000)
set @sql='DELETE dbo.Site_News_Article where ArticleID in ('+@ArticleID+')'
exec (@sql)
--[AllDnn_NewsPublish_DeleteArticleByArticle] '50,51' ......