?? 6343.htm
字號(hào):
<!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基礎(chǔ)教程:數(shù)據(jù)庫索引 - 編程入門網(wǎng)</title>
<meta name="keywords" content="MS SQL基礎(chǔ)教程:數(shù)據(jù)庫索引">
<meta name="description" content="MS SQL基礎(chǔ)教程:數(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)絡(luò)技術(shù)</a> | <a href='/OS/index.htm'>操作系統(tǒng)</a> | <a href='/Servers/index.htm'>服務(wù)器</a> | <a href='/web/index.htm'>網(wǎng)頁設(shè)計(jì)</a> | <a href='/Design/index.htm'>圖形設(shè)計(jì)</a> | <a href='/Office/index.htm'>辦公軟件</a> | <a href='/soft/index.htm'>常用軟件</a> | <a href='/shadu/index.htm'>殺毒頻道</a> | <a href='/PC/index.htm'>學(xué)電腦</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"> → 當(dāng)前位置:<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基礎(chǔ)教程:數(shù)據(jù)庫索引 </h3>
發(fā)布時(shí)間:2007-12-25 來源:網(wǎng)絡(luò)/責(zé)編:編程入門 作者:佚名<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> 用戶對(duì)數(shù)據(jù)庫最頻繁的操作是進(jìn)行數(shù)據(jù)查詢。一般情況下,數(shù)據(jù)庫在進(jìn)行查詢操作時(shí)需要對(duì)整個(gè)表進(jìn)行數(shù)據(jù)搜索。當(dāng)表中的數(shù)據(jù)很多時(shí),搜索數(shù)據(jù)就需要很長的時(shí)間,這就造成了服務(wù)器的資源浪費(fèi)。為了提高檢索數(shù)據(jù)的能力,數(shù)據(jù)庫引入了索引機(jī)制。本章將介紹索引的概念及其創(chuàng)建與管理。</p>
<p> 8.1.1 索引的概念</p>
<p> 索引是一個(gè)單獨(dú)的、物理的數(shù)據(jù)庫結(jié)構(gòu),它是某個(gè)表中一列或若干列值的集合和相應(yīng)的指向表中物理標(biāo)識(shí)這些值的數(shù)據(jù)頁的邏輯指針清單。索引是依賴于表建立的,它提供了數(shù)據(jù)庫中編排表中數(shù)據(jù)的內(nèi)部方法。一個(gè)表的存儲(chǔ)是由兩部分組成的,一部分用來存放表的數(shù)據(jù)頁面,另一部分存放索引頁面。索引就存放在索引頁面上,通常,索引頁面相對(duì)于數(shù)據(jù)頁面來說小得多。當(dāng)進(jìn)行數(shù)據(jù)檢索時(shí),系統(tǒng)先搜索索引頁面,從中找到所需數(shù)據(jù)的指針,再直接通過指針從數(shù)據(jù)頁面中讀取數(shù)據(jù)。從某種程度上,可以把數(shù)據(jù)庫看作一本書,把索引看作書的目錄,通過目錄查找書中的信息,顯然較沒有目錄的書方便、快捷。---www.bianceng.cn</p>
<p> 索引和關(guān)鍵字及約束有較大的聯(lián)系。關(guān)鍵字可以分為兩類:一種是邏輯關(guān)鍵字,即在 “數(shù)據(jù)庫基礎(chǔ)章”節(jié)中介紹的;另一種是物理關(guān)鍵字,它用來定義索引的列,也即索引。</p>
<p> 8.1.2 索引的結(jié)構(gòu)</p>
<p> (1) 索引的B-樹結(jié)構(gòu)</p>
<p> SQL Server 中的索引是以B-樹結(jié)構(gòu)來維護(hù)的,如圖8-1 所示。B-樹是一個(gè)多層次、自維護(hù)的結(jié)構(gòu)。一個(gè)B-樹包括一個(gè)頂層,稱為根節(jié)點(diǎn)(Root Node);0 到多個(gè)中間層(Intermediate);一個(gè)底層(Level 0),底層中包括若干葉子節(jié)點(diǎn)(Leaf Node)。在圖 8-1 中,每個(gè)方框代表一個(gè)索引頁,索引列的寬度越大,B-樹的深度越深,即層次越多,</p>
<p> <img onclick="get_larger(this)" alt="" src="/upimg/071226/11b61193P6019340.gif" /></p>
<p> 讀取記錄所要訪問的索引頁就越多。也就是說,數(shù)據(jù)查詢的性能將隨索引列層次數(shù)目的增加而降低。 圖8-1 索引的B-樹結(jié)構(gòu)</p>
<p> 在SQL Server 的數(shù)據(jù)庫中按存儲(chǔ)結(jié)構(gòu)的不同將索引分為兩類:簇索引(Clustered Index)和非簇索引(Nonclustered Index)。</p>
<p> (2) 簇索引簇索引對(duì)表的物理數(shù)據(jù)頁中的數(shù)據(jù)按列進(jìn)行排序,然后再重新存儲(chǔ)到磁盤上,即簇索引與數(shù)據(jù)是混為一體,的它的葉節(jié)點(diǎn)中存儲(chǔ)的是實(shí)際的數(shù)據(jù)。由于簇索引對(duì)表中的數(shù)據(jù)一一進(jìn)行了排序,因此用簇索引查找數(shù)據(jù)很快。但由于簇索引將表的所有數(shù)據(jù)完全重新排列了,它所需要的空間也就特別大,大概相當(dāng)于表中數(shù)據(jù)所占空間的120% 。表的數(shù)據(jù)行只能以一種排序方式存儲(chǔ)在磁盤上,所以一個(gè)表只能有一個(gè)簇索引。</p>
<p> (3) 非簇索引非簇索引具有與表的數(shù)據(jù)完全分離的結(jié)構(gòu),使用非簇索引不用將物理數(shù)據(jù)頁中的數(shù)據(jù)按列排序。非簇索引的葉節(jié)點(diǎn)中存儲(chǔ)了組成非簇索引的關(guān)鍵字的值和行定位器。行定位器的結(jié)構(gòu)和存儲(chǔ)內(nèi)容取決于數(shù)據(jù)的存儲(chǔ)方式。如果數(shù)據(jù)是以簇索引方式存儲(chǔ)的,則行定位器中存儲(chǔ)的是簇索引的索引鍵;如果數(shù)據(jù)不是以簇索引方式存儲(chǔ)的,這種方式又稱為堆存儲(chǔ)方式(Heap Structure),則行定位器存儲(chǔ)的是指向數(shù)據(jù)行的指針。非簇索引將行定位器按關(guān)鍵字的值用一定的方式排序,這個(gè)順序與表的行在數(shù)據(jù)頁中的排序是不匹配的。由于非簇索引使用索引頁存儲(chǔ)因此它比簇索引需要更多的存儲(chǔ)空間且檢索效率較低但一個(gè)表只能建一個(gè)簇索引,當(dāng)用戶需要建立多個(gè)索引時(shí)就需要使用非簇索引了。從理論上講,一個(gè)表最多可以建249 個(gè)非簇索引。</p>
<p> <a href="/data/SQLServer/jc/200712/6352.htm">查看全套"MS SQL入門基礎(chǔ)教程"</a></p><center><br /><script src="/js1/4682.js"></script></center>
<p>上一篇:<a href='/data/SQLServer/jc/200712/6342.htm'>MS SQL基礎(chǔ)教程:SQL表的刪除</a> 下一篇:<a href='/data/SQLServer/jc/200712/6344.htm'>MS SQL基礎(chǔ)教程:創(chuàng)建索引</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>相關(guān)文章</strong><br /><table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6342.htm">MS SQL基礎(chǔ)教程:SQL表的刪除</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6344.htm">MS SQL基礎(chǔ)教程:創(chuàng)建索引</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6341.htm">MS SQL基礎(chǔ)教程:查看表</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6345.htm">MS SQL基礎(chǔ)教程:查看與修改索引</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6340.htm">MS SQL基礎(chǔ)教程:SQL數(shù)據(jù)庫表的修改</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6346.htm">MS SQL基礎(chǔ)教程:刪除索引</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6339.htm">MS SQL基礎(chǔ)教程:自定義數(shù)據(jù)類型</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6347.htm">MS SQL基礎(chǔ)教程:索引調(diào)整向?qū)?lt;/a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6338.htm">MS SQL基礎(chǔ)教程:創(chuàng)建和使用約束</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6348.htm">MS SQL基礎(chǔ)教程:創(chuàng)建和使用圖表</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6337.htm">MS SQL基礎(chǔ)教程:創(chuàng)建數(shù)據(jù)庫表</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6349.htm">MS SQL基礎(chǔ)教程:數(shù)據(jù)完整性概述</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6336.htm">MS SQL基礎(chǔ)教程:實(shí)例數(shù)據(jù)庫</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6335.htm">MS SQL基礎(chǔ)教程:系統(tǒng)數(shù)據(jù)庫</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基礎(chǔ)教程:存儲(chǔ)過程</a><br/>
·<a href="/data/SQLServer/jc/200705/1189.htm">sql語言教程</a><br/>
·<a href="/data/SQLServer/jc/200807/10973.htm">MS SQL基礎(chǔ)教程:創(chuàng)建存儲(chǔ)</a><br/>
·<a href="/data/SQLServer/jc/200705/1182.htm">sql字符串函數(shù)</a><br/>
·<a href="/data/SQLServer/jc/200712/6301.htm">MS SQL基礎(chǔ)教程:SQL Serve</a><br/>
·<a href="/data/SQLServer/jc/200712/6302.htm">MS SQL基礎(chǔ)教程:SQL Serve</a><br/>
·<a href="/data/SQLServer/jc/200712/6314.htm">MS SQL基礎(chǔ)教程:數(shù)據(jù)類型</a><br/>
·<a href="/data/SQLServer/jc/200705/1188.htm">Sql語言基礎(chǔ)</a><br/>
·<a href="/data/SQLServer/jc/200712/6311.htm">MS SQL基礎(chǔ)教程:Transact-</a><br/>
·<a href="/data/SQLServer/jc/200712/6312.htm">MS SQL基礎(chǔ)教程:SQL變量</a><br/>
·<a href="/data/SQLServer/jc/200705/1184.htm">sql基本語句</a><br/>
·<a href="/data/SQLServer/jc/200807/10972.htm">MS SQL基礎(chǔ)教程:管理存儲(chǔ)</a><br/>
·<a href="/data/SQLServer/jc/200712/6306.htm">MS SQL基礎(chǔ)教程:數(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="將本站設(shè)為你的首頁" onclick="this.style.behavior='url(#default#homepage)';this.sethomepage('http://www.bianceng.cn');return false;" href="http://www.bianceng.cn/">設(shè)為首頁</a> | <a class="navmenu"
title="將本站加入到你的收藏夾"
href="javascript:window.external.AddFavorite(location.href,document.title)">加入收藏</a> | <a href="/about/about.htm">關(guān)于本站</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=6343&mid=0" language="javascript"></script></td>
</tr>
</table>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -