?? 6205.htm
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MS SQL基礎教程:數(shù)據(jù)庫中的鎖 - 編程入門網(wǎng)</title>
<meta name="keywords" content="MS SQL基礎教程:數(shù)據(jù)庫中的鎖">
<meta name="description" content="MS SQL基礎教程:數(shù)據(jù)庫中的鎖">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="/images/style.css" rel="stylesheet" type="text/css" />
<script src="/js1/head.js"></script>
</head>
<body leftmargin="0" topmargin="0" bgcolor="#efefef" oncopy=nocopy()>
<TABLE width="760" cellPadding="0" cellSpacing="0" bgcolor="#eff7fe" align="center">
<TR>
<TD><a href="/index.htm"><img src="/images/logo1.gif" width="150" height="60" border="0"></a></TD>
<TD width="470" align="right"><script src="/js1/top.js"></script></TD>
<TD width="125" align="center"><script src="/js1/topsy.js"></script></TD>
</TR>
</TABLE>
<table width="760" border="0" cellpadding="1" cellspacing="0" class="bklan" align="center">
<tr>
<td align="center" bgcolor="#eff7fe" height="24"> | <a href='/Programming/index.htm'>編程語言</a> | <a href='/webkf/index.htm'>web開發(fā)</a> | <a href='/data/index.htm'>數(shù)據(jù)庫</a> | <a href='/Network/index.htm'>網(wǎng)絡技術(shù)</a> | <a href='/OS/index.htm'>操作系統(tǒng)</a> | <a href='/Servers/index.htm'>服務器</a> | <a href='/web/index.htm'>網(wǎng)頁設計</a> | <a href='/Design/index.htm'>圖形設計</a> | <a href='/Office/index.htm'>辦公軟件</a> | <a href='/soft/index.htm'>常用軟件</a> | <a href='/shadu/index.htm'>殺毒頻道</a> | <a href='/PC/index.htm'>學電腦</a> |</td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="760" align="center" bgcolor="#ffffff" border="0">
<tr>
<td align="center"><script src="/js1/content1.js"></script></td>
</tr>
</table>
<table width="760" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="25" background="/templets/img/31bg3.gif" align="left" class="guidet"> → 當前位置:<a href='http://www.bianceng.cn/'>首頁</a>→<a href='/data/index.htm'>數(shù)據(jù)庫</a>→<a href='/data/SQLServer/index.htm'>SQL Server</a>→<a href='/data/SQLServer/jc/index.htm'>SQL Server教程</a>→正文</td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td valign="top" class="guidet" width="595"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="ct">
<tr>
<td align="center" valign="middle" class="til"><h3> MS SQL基礎教程:數(shù)據(jù)庫中的鎖 </h3>
發(fā)布時間:2007-12-25 來源:網(wǎng)絡/責編:編程入門 作者:佚名<br />
<script src="/js1/468.js"></script>
</td>
</tr>
<tr>
<td style="font-size:14px" align="left" class="til"><table border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><script src="/js1/300.js"></script></td>
</tr>
</table><p> 11.5.1 鎖的概念</p>
<p> 鎖(Lock) 是在多用戶環(huán)境下對資源訪問的一種限制。機制當對一個數(shù)據(jù)源加鎖后,此數(shù)據(jù)源就有了一定的訪問限制。我們就稱對此數(shù)據(jù)源進行了“鎖定”。在SQL Server中,可以對以下的對象進行鎖定: </p>
數(shù)據(jù)行(Row):數(shù)據(jù)頁中的單行數(shù)據(jù); 索引行(Key):索引頁中的單行數(shù)據(jù),即索引的鍵值; 頁(Page):頁是SQL Server 存取數(shù)據(jù)的基本單位,其大小為8KB; 盤區(qū)(Extent):一個盤區(qū)由8 個連續(xù)的頁組成; 表(Table); 數(shù)據(jù)庫(Database)。 11.5.2 鎖的類別
<p> 在SQL Server 中,鎖有兩種分類方法。</p>
<p> (1) 從數(shù)據(jù)庫系統(tǒng)的角度來看</p>
<p> 鎖分為以下三種類型: </p>
獨占鎖(Exclusive Lock)
<p> 獨占鎖鎖定的資源只允許進行鎖定操作的程序使用,其它任何對它的操作均不會被接受。執(zhí)行數(shù)據(jù)更新命令,即INSERT、 UPDATE 或DELETE 命令時,SQL Server 會自動使用獨占鎖。但當對象上有其它鎖存在時,無法對其加獨占鎖。獨占鎖一直到事務結(jié)束才能被釋放。 共享鎖(Shared Lock)</p>
<p> 共享鎖鎖定的資源可以被其它用戶讀取,但其它用戶不能修改它。在SELECT 命令執(zhí)行時,SQL Server 通常會對對象進行共享鎖鎖定。通常加共享鎖的數(shù)據(jù)頁被讀取完畢后,共享鎖就會立即被釋放。 更新鎖(Update Lock)</p>
<p> 更新鎖是為了防止死鎖而設立的。當SQL Server 準備更新數(shù)據(jù)時,它首先對數(shù)據(jù)對象作更新鎖鎖定,這樣數(shù)據(jù)將不能被修改,但可以讀取。等到SQL Server 確定要進行更新數(shù)據(jù)操作時,它會自動將更新鎖換為獨占鎖。但當對象上有其它鎖存在時,無法對其作更新鎖鎖定。 </p>
(2)從程序員的角度看
<p> 鎖分為以下兩種類型: </p>
樂觀鎖(Optimistic Lock)
<p> 樂觀鎖假定在處理數(shù)據(jù)時,不需要在應用程序的代碼中做任何事情就可以直接在記錄上加鎖、即完全依靠數(shù)據(jù)庫來管理鎖的工作。一般情況下,當執(zhí)行事務處理時SQL Server會自動對事務處理范圍內(nèi)更新到的表做鎖定。 悲觀鎖(Pessimistic Lock)</p>
<div></div>
<center>共3頁: 上一頁 1 <a href='6205_2.htm'>[2]</a> <a href='6205_3.htm'>[3]</a> <a href='6205_2.htm'>下一頁</a> <br /><script src="/js1/4682.js"></script></center>
<p>上一篇:<a href='/data/SQLServer/jc/200712/6204.htm'>MS SQL基礎教程:SQL數(shù)據(jù)庫中的事務</a> 下一篇:<a href='/data/SQLServer/jc/200712/6206.htm'>MS SQL基礎教程:觸發(fā)器概述</a> </p></td>
</tr>
<tr>
<td align="left" style="font-size:14px;" height="25"><IMG src="/images/t0.gif" width="12" height="12" align=absMiddle><strong>相關文章</strong><br /><table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6204.htm">MS SQL基礎教程:SQL數(shù)據(jù)庫中的事務</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6206.htm">MS SQL基礎教程:觸發(fā)器概述</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6203.htm">MS SQL基礎教程:更新數(shù)據(jù)</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6207.htm">MS SQL基礎教程:創(chuàng)建觸發(fā)器</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6202.htm">MS SQL基礎教程:刪除數(shù)據(jù)</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6208.htm">MS SQL基礎教程:觸發(fā)器的原理</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6201.htm">MS SQL基礎教程:數(shù)據(jù)庫全文檢索</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6209.htm">MS SQL基礎教程:INSTEAD OF觸發(fā)器</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6200.htm">MS SQL基礎教程:存儲查詢結(jié)果</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6210.htm">MS SQL基礎教程:觸發(fā)器的應用</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6199.htm">MS SQL基礎教程:合并查詢</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6211.htm">MS SQL基礎教程:觸發(fā)器的高級應用</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6198.htm">MS SQL基礎教程:嵌套查詢</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6212.htm">MS SQL基礎教程:管理觸發(fā)器</a><br/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="165" valign="top" class="guideb"><script src="/js1/1601.js"></script><table width="100%" border="0" cellpadding="0" cellspacing="0" valign="top">
<tr>
<td height="25" align="center" background="/templets/img/31bg3.gif"><strong>閱讀排行</strong></td>
</tr>
<tr>
<td>·<a href="/data/SQLServer/jc/200712/6352.htm">MS SQL Server入門教程</a><br/>
·<a href="/data/SQLServer/jc/200807/10974.htm">MS SQL基礎教程:存儲過程</a><br/>
·<a href="/data/SQLServer/jc/200705/1189.htm">sql語言教程</a><br/>
·<a href="/data/SQLServer/jc/200807/10973.htm">MS SQL基礎教程:創(chuàng)建存儲</a><br/>
·<a href="/data/SQLServer/jc/200705/1182.htm">sql字符串函數(shù)</a><br/>
·<a href="/data/SQLServer/jc/200712/6301.htm">MS SQL基礎教程:SQL Serve</a><br/>
·<a href="/data/SQLServer/jc/200712/6302.htm">MS SQL基礎教程:SQL Serve</a><br/>
·<a href="/data/SQLServer/jc/200712/6314.htm">MS SQL基礎教程:數(shù)據(jù)類型</a><br/>
·<a href="/data/SQLServer/jc/200705/1188.htm">Sql語言基礎</a><br/>
·<a href="/data/SQLServer/jc/200712/6311.htm">MS SQL基礎教程:Transact-</a><br/>
·<a href="/data/SQLServer/jc/200712/6312.htm">MS SQL基礎教程:SQL變量</a><br/>
·<a href="/data/SQLServer/jc/200705/1184.htm">sql基本語句</a><br/>
·<a href="/data/SQLServer/jc/200807/10972.htm">MS SQL基礎教程:管理存儲</a><br/>
·<a href="/data/SQLServer/jc/200712/6306.htm">MS SQL基礎教程:數(shù)據(jù)庫基</a><br/>
·<a href="/data/SQLServer/jc/200705/1178.htm">sql數(shù)據(jù)表</a><br/>
</td>
</tr>
<tr>
<td><script src="/js1/1602.js"></script></td>
</tr>
<tr>
<td height="25" align="center" background="/templets/img/31bg3.gif"><strong>最新文章</strong></td>
</tr>
<tr>
<td><script src="/plus/js/0.js" language="javascript"></script></td>
</tr>
</table></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="760" align="center" bgcolor="#ffffff" border="0">
<tr>
<td align="center"><script src="/js1/content2.js"></script></td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr height="26">
<td bgcolor="#e1f0fd" width="48"></td>
<td bgcolor="#6ab3f4" width="35"></td>
<td bgcolor="#0a518f" colspan="2" width="4"></td>
<td bgcolor="#c0c0c0" width="530" align="center"><a title="將本站設為你的首頁" onclick="this.style.behavior='url(#default#homepage)';this.sethomepage('http://www.bianceng.cn');return false;" href="http://www.bianceng.cn/">設為首頁</a> | <a class="navmenu"
title="將本站加入到你的收藏夾"
href="javascript:window.external.AddFavorite(location.href,document.title)">加入收藏</a> | <a href="/about/about.htm">關于本站</a> | <a href="/plus/flink.php">友情鏈接</a> | <a href="/about/banquan.htm">版權(quán)聲明</a> | <a href="/plus/sitemap.html">網(wǎng)站地圖</a> | <a href="/plus/rssmap.html">RSS訂閱</a></td>
<td bgcolor="#0a518f" colspan="2" width="4"></td>
<td bgcolor="#6ab3f4" width="32"></td>
<td bgcolor="#e1f0fd" width="47"></td>
</tr>
<tr height="26">
<td colspan="9" bgcolor="#FFFFFF" align="center">編程入門網(wǎng) 版權(quán)所有,bianceng.cn,All Rights Reserved. <script src="/js/tongji.js"></script> 閱讀次數(shù):<script src="/plus/count.php?aid=6205&mid=0" language="javascript"></script></td>
</tr>
</table>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -