
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
	<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head><card id="MainCard" title="&#x6B22;&#x8FCE;&#x5149;&#x4E34;"><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a><br/>&nbsp;</p><p><b>&#x6807;&#x9898;&#x3A;</b> &#x53;&#x51;&#x4C;&#x20;&#x53;&#x65;&#x72;&#x76;&#x65;&#x72;&#x32;&#x30;&#x30;&#x30;&#x4F7F;&#x7528;&#x884C;&#x9501;&#x89E3;&#x51B3;&#x5E76;&#x53D1;&#x5E93;&#x5B58;&#x4E3A;&#x8D1F;&#x8D85;&#x5356;&#x95EE;&#x9898;</p><p><b>&#x4F5C;&#x8005;&#x3A;</b> &#x64;&#x6E;&#x61;&#x77;&#x6F;</p><p><b>&#x65E5;&#x671F;&#x3A;</b> &#x32;&#x30;&#x31;&#x34;&#x2D;&#x30;&#x34;&#x2D;&#x31;&#x36;&#x20;&#x30;&#x33;&#x3A;&#x35;&#x34;&#x20;&#x50;&#x4D;</p><p><b>&#x5206;&#x7C7B;&#x3A;</b> <a href="wap.asp?do=showLog&amp;cateID=7">&#x670D;&#x52A1;&#x5668;</a></p><p><b>&#x5185;&#x5BB9;&#x3A;</b> &#x5047;&#x8BBE;&#x5E93;&#x5B58;&#x8868;&#x7ED3;&#x6784;&#x53CA;&#x6570;&#x636E;&#x5982;&#x4E0B;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;cr&#101;ate table Stock<br/>(<br/>&#160;&#160;&#160;&#160;Id int identity(1,1) primary key,<br/>&#160;&#160;&#160;&#160;Name nvarchar(50),<br/>&#160;&#160;&#160;&#160;Quantity int<br/>)<br/>--ins&#101;rt<br/>ins&#101;rt into Stock sel&#101;ct &#39;orange&#39;,10<br/>&#x5728;&#x79D2;&#x6740;&#x7B49;&#x9AD8;&#x5E76;&#x53D1;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#x4F1A;&#x5BFC;&#x81F4;&#x5E93;&#x5B58;&#x4E3A;&#x8D1F;&#x4EA7;&#x751F;&#x8D85;&#x5356;&#x95EE;&#x9898;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;cr&#101;ate procedure [dbo].Sale<br/>&nbsp;&nbsp;&nbsp;&nbsp;@name nvarchar(50),<br/>&nbsp;&nbsp;&nbsp;&nbsp;@number int,<br/>&nbsp;&nbsp;&nbsp;&nbsp;@result bit output<br/>as<br/>begin tran<br/>declare @Quantity int<br/>sel&#101;ct @Quantity=Quantity from Stock wh&#101;re Name=@name<br/>if @Quantity&gt;=@number begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;waitfor delay &#39;00:00:10&#39; --todo<br/>&nbsp;&nbsp;&nbsp;&nbsp;up&#100;ate Stock set Quantity=Quantity-@number wh&#101;re Name=@name<br/>end<br/>if @@rowcount&gt;0 begin<br/>&#160;&#160;&#160;&#160;sel&#101;ct @result=1<br/>&#160;&#160;&#160;&#160;commit<br/>end<br/>else begin<br/>&#160;&#160;&#160;&#160;sel&#101;ct @result=0<br/>&#160;&#160;&#160;&#160;rollback<br/>end<br/>go<br/>&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5BF9;&#x884C;&#x4F7F;&#x7528;&#x6392;&#x4ED6;&#x9501;(X&#x9501;)&#x6765;&#x89E3;&#x51B3;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;cr&#101;ate procedure [dbo].Sale<br/>&nbsp;&nbsp;&nbsp;&nbsp;@name nvarchar(50),<br/>&nbsp;&nbsp;&nbsp;&nbsp;@number int,<br/>&nbsp;&nbsp;&nbsp;&nbsp;@result bit output<br/>as<br/>begin tran<br/>declare @Quantity int<br/>sel&#101;ct @Quantity=Quantity from Stock with(ROWLOCK,XLOCK) wh&#101;re Name=@name<br/>if @Quantity&gt;=@number begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;waitfor delay &#39;00:00:10&#39; --todo<br/>&nbsp;&nbsp;&nbsp;&nbsp;up&#100;ate Stock set Quantity=Quantity-@number wh&#101;re Name=@name<br/>end<br/>if @@rowcount&gt;0 begin<br/>&#160;&#160;&#160;&#160;sel&#101;ct @result=1<br/>&#160;&#160;&#160;&#160;commit<br/>end<br/>else begin<br/>&#160;&#160;&#160;&#160;sel&#101;ct @result=0<br/>&#160;&#160;&#160;&#160;rollback<br/>end<br/>go<br/>&#x8865;&#x5145;&#x8BF4;&#x660E;<br/>[1].&#x4E0D;&#x7528;&#x884C;&#x9501;&#x65F6;&#xFF0C;&#x51CF;&#x5E93;&#x5B58;&#x7528;Quantity=@Quantity-@number&#x95EE;&#x9898;&#x66F4;&#x4E25;&#x91CD;&#xFF0C;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x4E3A;&#x8D1F;&#x7684;&#x95EE;&#x9898;&#x4E86;&#xFF1B;<br/>[2].XLOCK&#x7684;&#x4F5C;&#x7528;&#x6709;&#x4E24;&#x70B9;&#xFF1A;&#x4E00;&#x662F;&#x8BF4;&#x660E;&#x9501;&#x6A21;&#x5F0F;&#x4E3A;&#x6392;&#x4ED6;&#x9501;&#xFF0C;&#x4E8C;&#x662F;&#x5EF6;&#x957F;&#x884C;&#x9501;&#x65F6;&#x95F4;&#x81F3;&#x4E8B;&#x52A1;&#x7ED3;&#x675F;&#x3002;&#x82E5;&#x7701;&#x7565;XLOCK&#x4ECD;&#x4F1A;&#x4EA7;&#x751F;&#x8D85;&#x5356;&#x95EE;&#x9898;&#xFF1B;<br/>[3].&#x9501;&#x6A21;&#x5F0F;&#x6709;&#x5171;&#x4EAB;&#x9501;(HOLDLOCK)&#x3001;&#x66F4;&#x65B0;&#x9501;(UPDLOCK)&#x548C;&#x6392;&#x4ED6;&#x9501;(XLOCK)&#xFF0C;&#x8003;&#x8651;&#x5C06;&#x4E0A;&#x8FB9;XLOCK&#x6539;&#x4E3A;HOLDLOCK&#x7ED3;&#x679C;&#x4F1A;&#x600E;&#x6837;&#xFF1F;<br/>--------------------------------------------------------------------------------------------------------<br/>&#x6709;&#x7F51;&#x53CB;&#x63D0;&#x4F9B;&#x4E86;&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x7531;&#x4E8E;up&#100;ate&#x8BED;&#x53E5;&#x672C;&#x8EAB;&#x5177;&#x6709;&#x6392;&#x4ED6;&#x9501;&#xFF0C;&#x56E0;&#x800C;&#x7528;&#x4E0B;&#x8FB9;&#x65B9;&#x6CD5;&#x4E5F;&#x662F;&#x53EF;&#x4EE5;&#x7684;&#xFF1A;<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;cr&#101;ate procedure [dbo].Sale<br/>&nbsp;&nbsp;&nbsp;&nbsp;@name nvarchar(50),<br/>&nbsp;&nbsp;&nbsp;&nbsp;@number int,<br/>&nbsp;&nbsp;&nbsp;&nbsp;@result bit output<br/>as<br/>begin tran<br/>declare @Quantity int<br/>sel&#101;ct @Quantity=Quantity from Stock wh&#101;re Name=@name<br/>if @Quantity&gt;=@number begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;waitfor delay &#39;00:00:10&#39; --todo<br/>&nbsp;&nbsp;&nbsp;&nbsp;up&#100;ate Stock set Quantity=Quantity-@number wh&#101;re Name=@name and Quantity&gt;=@number<br/>end<br/>if @@rowcount&gt;0 begin<br/>&#160;&#160;&#160;&#160;sel&#101;ct @result=1<br/>&#160;&#160;&#160;&#160;commit<br/>end<br/>else begin<br/>&#160;&#160;&#160;&#160;sel&#101;ct @result=0<br/>&#160;&#160;&#160;&#160;rollback<br/>end<br/>go</p><p> + <a href="#CommentCard">&#x67E5;&#x770B;&#x5F53;&#x524D;&#x65E5;&#x5FD7;&#x8BC4;&#x8BBA;</a> (0)</p><p>&nbsp;<br/><br/><a href="wap.asp?do=Login">&#x767B;&#x5F55;</a></p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.031&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card><card id="postCommentCard"><p><b>&#x6807;&#x9898;&#x3A;</b> <a href="#MainCard">&#x53;&#x51;&#x4C;&#x20;&#x53;&#x65;&#x72;&#x76;&#x65;&#x72;&#x32;&#x30;&#x30;&#x30;&#x4F7F;&#x7528;&#x884C;&#x9501;&#x89E3;&#x51B3;&#x5E76;&#x53D1;&#x5E93;&#x5B58;&#x4E3A;&#x8D1F;&#x8D85;&#x5356;&#x95EE;&#x9898;</a></p><p><br/>你没有权限发表评论</p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.031&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card><card id="CommentCard"><p>&#x6682;&#x65E0;&#x8BC4;&#x8BBA;</p><p><a href="#MainCard">&#x8FD4;&#x56DE;</a></p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.031&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card>
</wml>
