﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-I love .net</title><link>http://www.cnblogs.com/tianqing/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 14 Oct 2008 02:47:21 GMT</lastBuildDate><pubDate>Tue, 14 Oct 2008 02:47:21 GMT</pubDate><ttl>60</ttl><item><title>SQL Server2005探索之---正确使用索引SQL案例补充</title><link>http://www.cnblogs.com/tianqing/archive/2008/08/07/1263093.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Thu, 07 Aug 2008 09:01:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/08/07/1263093.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1263093.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/08/07/1263093.html#Feedback</comments><slash:comments>25</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1263093.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1263093.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp; 应上篇文章"<a class="titlelnk" href="http://www.cnblogs.com/tianqing/archive/2008/08/07/1262603.html"><font color="#333333">SQL Server2005探索之---正确使用索引</font></a>"朋友们的需要，将如何正确使用索引结合几个SQL索引使用说明作为补充。</p>
<p>&nbsp;&nbsp; 数据库： Northwind</p>
<p>&nbsp;&nbsp; SQL Server 版本： SQL Server2005</p>
<p>&nbsp;&nbsp; 操作之前执行如下sql：dbcc freeproccache&nbsp;&nbsp;&nbsp;&nbsp; 以清空缓存，执行&#8220;SET STATISTICS IO ON &#8221;，查看执行成本。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbcc dropcleanbuffers</p>
<p>&nbsp;&nbsp; 1. 不要对数据进行计算</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_162834" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_162834').style.display='none'; document.getElementById('Code_Open_Image_162834').style.display='inline'; document.getElementById('Code_Open_Text_162834').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_162834" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_162834').style.display='none'; getElementById('Code_Closed_Image_162834').style.display='inline'; getElementById('Code_Closed_Text_162834').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_162834">Code</span><span id="Code_Open_Text_162834" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">USE</span><span style="color: #000000">&nbsp;Northwind;<br />
</span><span style="color: #0000ff">GO</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">SELECT</span><span style="color: #000000">&nbsp;CustomerID,OrderID,ShipName&nbsp;</span><span style="color: #0000ff">FROM</span><span style="color: #000000">&nbsp;orders&nbsp;</span><span style="color: #0000ff">WHERE</span><span style="color: #000000">&nbsp;CustomerID&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">VINET</span><span style="color: #ff0000">'</span><span style="color: #000000">&nbsp;</span></span></div>
<p>执行成本：</p>
<p>表 'Orders'。扫描计数 1，逻辑读取 12 次，物理读取 0 次，预读 0 次，lob 逻辑读取 0 次，lob 物理读取 0 次，lob 预读 0 次。</p>
<p>执行计划：</p>
<p><img height="543" alt="" src="http://www.cnblogs.com/images/cnblogs_com/tianqing/sql1.jpg" width="787" border="0" />&nbsp;&nbsp; </p>
<p>执行分析：在上述SQL中WHERE条件中以CustomerID作为条件进行约束，正用到了Orders表中索引CustomerID，索引CustomerID以数据列CustomerID进行排序，SQL查询中利用了索引CustomerID配合二分法查找，很快检索了数据。</p>
<p>&nbsp;</p>
<div class="cnblogs_code">
<p><img id="Code_Closed_Image_163341" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_163341').style.display='none'; document.getElementById('Code_Open_Image_163341').style.display='inline'; document.getElementById('Code_Open_Text_163341').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_163341" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_163341').style.display='none'; getElementById('Code_Closed_Image_163341').style.display='inline'; getElementById('Code_Closed_Text_163341').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_163341">SQL</span></p>
<p><span id="Code_Open_Text_163341" style="display: none"><span style="color: #0000ff">USE</span><span style="color: #000000">&nbsp;Northwind;<br />
</span><span style="color: #0000ff">GO</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">SELECT</span><span style="color: #000000">&nbsp;CustomerID,OrderID,ShipName&nbsp;</span><span style="color: #0000ff">FROM</span><span style="color: #000000">&nbsp;orders&nbsp;</span><span style="color: #0000ff">WHERE</span><span style="color: #000000">&nbsp;CustomerID&nbsp;</span><span style="color: #808080">+</span><span style="color: #ff0000">'</span><span style="color: #ff0000">-</span><span style="color: #ff0000">'</span><span style="color: #808080">+</span><span style="color: #000000">ShipName</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">VINET-Vins&nbsp;et&nbsp;alcools&nbsp;Chevalier</span><span style="color: #ff0000">'</span><span style="color: #000000">&nbsp;</span></span></p>
</div>
<p>执行成本：</p>
<p>表 'Orders'。扫描计数 1，逻辑读取 22 次，物理读取 0 次，预读 0 次，lob 逻辑读取 0 次，lob 物理读取 0 次，lob 预读 0 次。</p>
<p>执行计划：</p>
<p><img height="514" alt="" src="http://www.cnblogs.com/images/cnblogs_com/tianqing/sqle.jpg" width="839" border="0" /></p>
<p>执行分析：</p>
<p>这上述SQL对CustomerID列进行计算，查询计划只好使用聚集索引扫描检索数据。</p>
<p><strong>执行比较：</strong></p>
<p><strong>&nbsp;&nbsp; </strong>合理使用索引：I/O costs：0.003125， CPU costs：0.0001625</p>
<p>&nbsp; 未合理使用索引：I/O costs: 0.0171991, CPU costs: 0.00107</p>
<p>2. WHERE条件对字段使用函数</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_171345" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_171345').style.display='none'; document.getElementById('Code_Open_Image_171345').style.display='inline'; document.getElementById('Code_Open_Text_171345').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_171345" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_171345').style.display='none'; getElementById('Code_Closed_Image_171345').style.display='inline'; getElementById('Code_Closed_Text_171345').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_171345">Code</span><span id="Code_Open_Text_171345" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">USE</span><span style="color: #000000">&nbsp;Northwind;<br />
</span><span style="color: #0000ff">GO</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">SELECT</span><span style="color: #000000">&nbsp;CustomerID,OrderID,ShipName&nbsp;</span><span style="color: #0000ff">FROM</span><span style="color: #000000">&nbsp;orders&nbsp;</span><span style="color: #0000ff">WHERE</span><span style="color: #000000">&nbsp;CustomerID&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">VINET</span><span style="color: #ff0000">'</span><span style="color: #000000">&nbsp;</span></span></div>
<p>&nbsp;</p>
<p>执行成本：</p>
<p>表 'Orders'。扫描计数 1，逻辑读取 12 次，物理读取 0 次，预读 0 次，lob 逻辑读取 0 次，lob 物理读取 0 次，lob 预读 0 次。</p>
<p>执行计划：</p>
<p><img height="543" alt="" src="http://www.cnblogs.com/images/cnblogs_com/tianqing/sql1.jpg" width="787" border="0" /></p>
<p>&nbsp;</p>
<p>对数据使用函数：</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_164158" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_164158').style.display='none'; document.getElementById('Code_Open_Image_164158').style.display='inline'; document.getElementById('Code_Open_Text_164158').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_164158" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_164158').style.display='none'; getElementById('Code_Closed_Image_164158').style.display='inline'; getElementById('Code_Closed_Text_164158').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_164158">Code</span><span id="Code_Open_Text_164158" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">USE</span><span style="color: #000000">&nbsp;Northwind;<br />
</span><span style="color: #0000ff">GO</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">SELECT</span><span style="color: #000000">&nbsp;CustomerID,OrderID,ShipName&nbsp;</span><span style="color: #0000ff">FROM</span><span style="color: #000000">&nbsp;orders&nbsp;</span><span style="color: #0000ff">WHERE</span><span style="color: #000000">&nbsp;</span><span style="color: #ff00ff">LOWER</span><span style="color: #000000">(CustomerID)&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">vinet</span><span style="color: #ff0000">'</span><span style="color: #000000">&nbsp;</span></span></div>
<p>执行成本：</p>
<p>表 'Orders'。扫描计数 1，逻辑读取 15 次，物理读取 0 次，预读 0 次，lob 逻辑读取 0 次，lob 物理读取 0 次，lob 预读 0 次。</p>
<p>执行计划：</p>
<p><img height="510" alt="" src="http://www.cnblogs.com/images/cnblogs_com/tianqing/sqlee.jpg" width="788" border="0" /></p>
<p><strong>执行比较：</strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 合理使用索引：I/O costs：0.003125， CPU costs：0.0001625 </p>
<p>&nbsp; 未合理使用索引：I/O costs: 0.0046065, CPU costs: 0.00107</p>
<p>3. 使用OR</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_164439" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_164439').style.display='none'; document.getElementById('Code_Open_Image_164439').style.display='inline'; document.getElementById('Code_Open_Text_164439').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_164439" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_164439').style.display='none'; getElementById('Code_Closed_Image_164439').style.display='inline'; getElementById('Code_Closed_Text_164439').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_164439">Code</span><span id="Code_Open_Text_164439" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">USE</span><span style="color: #000000">&nbsp;Northwind;<br />
</span><span style="color: #0000ff">GO</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">SELECT</span><span style="color: #000000">&nbsp;CustomerID,OrderID,ShipName&nbsp;</span><span style="color: #0000ff">FROM</span><span style="color: #000000">&nbsp;orders&nbsp;</span><span style="color: #0000ff">WHERE</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">CustomerID</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">vinet</span><span style="color: #ff0000">'</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">OR</span><span style="color: #000000">&nbsp;OrderID&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="font-weight: bold; color: #800000">10356</span></span></div>
<p>执行成本：</p>
<p>表 'Orders'。扫描计数 1，逻辑读取 22 次，物理读取 0 次，预读 0 次，lob 逻辑读取 0 次，lob 物理读取 0 次，lob 预读 0 次。</p>
<p>执行计划：</p>
<p><img height="548" alt="" src="http://www.cnblogs.com/images/cnblogs_com/tianqing/sqleee.jpg" width="836" border="0" /></p>
<p>将OR改为UNION</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_171613" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_171613').style.display='none'; document.getElementById('Code_Open_Image_171613').style.display='inline'; document.getElementById('Code_Open_Text_171613').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_171613" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_171613').style.display='none'; getElementById('Code_Closed_Image_171613').style.display='inline'; getElementById('Code_Closed_Text_171613').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_171613">Code</span><span id="Code_Open_Text_171613" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">USE</span><span style="color: #000000">&nbsp;Northwind;<br />
</span><span style="color: #0000ff">GO</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">SELECT</span><span style="color: #000000">&nbsp;CustomerID,OrderID,ShipName&nbsp;</span><span style="color: #0000ff">FROM</span><span style="color: #000000">&nbsp;orders&nbsp;</span><span style="color: #0000ff">WHERE</span><span style="color: #000000">&nbsp;CustomerID</span><span style="color: #808080">=</span><span style="color: #ff0000">'</span><span style="color: #ff0000">VINET</span><span style="color: #ff0000">'</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">UNION</span><span style="color: #000000"><br />
</span><span style="color: #0000ff">SELECT</span><span style="color: #000000">&nbsp;CustomerID,OrderID,ShipName&nbsp;</span><span style="color: #0000ff">FROM</span><span style="color: #000000">&nbsp;orders&nbsp;</span><span style="color: #0000ff">WHERE</span><span style="color: #000000">&nbsp;OrderID&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="font-weight: bold; color: #800000">10356</span></span></div>
<p>&nbsp;</p>
<p>执行成本：</p>
<p>表 'Orders'。扫描计数 1，逻辑读取 15 次，物理读取 0 次，预读 0 次，lob 逻辑读取 0 次，lob 物理读取 0 次，lob 预读 0 次。</p>
<p>执行计划:</p>
<p><img height="554" alt="" src="http://www.cnblogs.com/images/cnblogs_com/tianqing/sqleeeeee.jpg" width="975" border="0" /></p>
<p>执行比较：</p>
<p>使用OR： I/O costs：0.0171991 CPU：0.00107</p>
<p>不使用OR：I/O costs：0.003125 CPU：0.0001625</p>
<p>&nbsp;</p>
<p>总结： 通过上述SQL不同语法比较，可以看出合理使用SARG参数可以较好的利用索引，降低执行成本，提高效率。</p>
<img src ="http://www.cnblogs.com/tianqing/aggbug/1263093.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42977/" target="_blank">[新闻]微软首次打破先例 Windows 7不再改名</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>SQL Server2005探索之---正确使用索引</title><link>http://www.cnblogs.com/tianqing/archive/2008/08/07/1262603.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Thu, 07 Aug 2008 02:12:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/08/07/1262603.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1262603.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/08/07/1262603.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1262603.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1262603.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp; 最近在总结SQL Server2005下性能调优方法，一个通用的调优方法。通过找到系统的瓶颈，然后解决瓶颈，提高性能。例如：当我们找到系统的瓶颈在于磁盘I/O上，在不提高硬件配置的前提下，我们应该如果提高性能？通过各种各样的性能分析工具 ：Profiler、SQLDiag、Perfmon等等。我们找到了一些影响性能的关键SQL，现在我们暂不考虑程序问题。对于这些SQL我们应该如何改进呢？说起SQL，不得不提索引，这也就是我们今天要讨论的主题。</p>
<p>&nbsp; 首先，什么是索引？从BookOnline上search了一下：</p>
<fieldset><legend>索引</legend>&nbsp;&nbsp; 索引是与表或视图关联的磁盘上结构，可以加快从表或视图中检索行的速度。索引包含由表或视图中的一列或多列生成的键。这些键存储在一个结构（B 树）中，使 SQL Server 可以快速有效地查找与键值关联的行。 </fieldset>&nbsp; 索引有什么类型：
<fieldset><legend>索引类型</legend>
<li>聚集<br />
<ul>
    <li>聚集索引根据数据行的键值在表或视图中排序和存储这些数据行。索引定义中包含聚集索引列。每个表只能有一个聚集索引，因为数据行本身只能按一个顺序排序。</li>
    <li>只有当表包含聚集索引时，表中的数据行才按排序顺序存储。如果表具有聚集索引，则该表称为聚集表。如果表没有聚集索引，则其数据行存储在一个称为堆的无序结构中。 </li>
</ul>
</li>
<li>非聚集 <br />
<ul>
    <li>非聚集索引具有独立于数据行的结构。非聚集索引包含非聚集索引键值，并且每个键值项都有指向包含该键值的数据行的指针。</li>
    <li>从非聚集索引中的索引行指向数据行的指针称为行定位器。行定位器的结构取决于数据页是存储在堆中还是聚集表中。对于堆，行定位器是指向行的指针。对于聚集表，行定位器是聚集索引键。</li>
    <li>在 SQL Server 2005 中，可以向非聚集索引的叶级别添加非键列以跳过现有的索引键限制（900 字节和 16 键列），并执行完整范围内的索引查询。</li>
</ul>
</li>
</fieldset>
<p>&nbsp;&nbsp; 在了解了上述概念后，如何正确使用索引对于程序的性能有着至关重要的作用。设计良好的索引可以减少磁盘 I/O 操作，并且消耗的系统资源也较少，从而可以提高查询性能。对于包含 SELECT、UPDATE 或 DELETE 语句的各种查询，索引会很有用。</p>
<p>&nbsp;&nbsp; 在我们的coding中，得到相同的查询结果SQL的写法可以有多种，最重要的考虑因素之一是WHERE条件，WHERE条件限制了查询要返回的记录数目，查询优化程序会尝试判断已有的索引，分析对查找符合的记录是否有帮助。</p>
<p>&nbsp;&nbsp; 查询优化程序要查看WHERE中的条件，以决定这些条件在限制SQLServer访问时是否有用。所以，有效的设置查询参数，决定了是否可以充分的利用索引。</p>
<p>&nbsp;&nbsp; 查询参数可以包含一下操作：=、&lt;、&gt;、&gt;=、&lt;=、BETWEEN、部分like。其中，like当这样使用时会用到索引：like '*%',但like'%*'就用不到索引。因为索引的摆放是依据字段值升序或降序排列，like'%*'这种用法，不能利用有序的数据结构，利用二分法查找数据。</p>
<p>&nbsp; 不适当的查询参数有：NOT 、!= 、&lt;&gt;、 !&gt;、 !&lt; 、NOT EXISTS、 NOT IN 、NOT LIKE等，还有一些不当的用法，例如：对数据进行计算，负向查询、等号左边使用函数、使用OR。上述语法都不用不上索引，降低程序的效率。</p>
<p>&nbsp;&nbsp; 当我们了解了索引的用法后，在我们编写sql时考虑上述用法，充分利用索引，以高程序的性能。还有，在我们coding过程中，写好sql后，最好使用SQL Server自带的查询计划，来分析SQL执行成本、索引的使用情况，尽可能的使用索引来提高效率。</p>
<p>&nbsp;&nbsp; 先说这么多，欢迎高手们提出更好的建议，我们一起进步。</p>
<img src ="http://www.cnblogs.com/tianqing/aggbug/1262603.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42977/" target="_blank">[新闻]微软首次打破先例 Windows 7不再改名</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>SQL Server2005探索之——分区，请朋友们讨论说说</title><link>http://www.cnblogs.com/tianqing/archive/2008/07/17/1245036.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Thu, 17 Jul 2008 03:09:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/07/17/1245036.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1245036.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/07/17/1245036.html#Feedback</comments><slash:comments>10</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1245036.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1245036.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; <span lang="EN-US" style="font-size: 10.5pt; font-family: 'Calibri','sans-serif'; mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-font-kerning: 1.0pt">SQL Server 2005</span><span style="font-size: 10.5pt; font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-font-kerning: 1.0pt">是微软在推出</span><span lang="EN-US" style="font-size: 10.5pt; font-family: 'Calibri','sans-serif'; mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-font-kerning: 1.0pt">SQL Server 2000</span><span style="font-size: 10.5pt; font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-font-kerning: 1.0pt">后时隔五年推出的一个数据库.相对于SQL Server2000来说有了质的提高。它给我们提供了诸多新特性，例如：复制、分区、动态管理视图、CTE、性能顾问等等。现在，就这个帖子，和园子里的朋友们讨论一下分区。<br />
&nbsp;&nbsp; 在微软TechNet上是这样介绍分区表和分区索引的：</span><br />
<fieldset><legend>Instruction</legend>&nbsp;&nbsp; 已分区表和已分区索引的数据划分为分布于一个数据库中多个文件组的单元。数据是按水平方式分区的，因此多组行映射到单个的分区。对数据进行查询或更新时，表或索引将被视为单个逻辑实体。单个索引或表的所有分区都必须位于同一个数据库中。<br />
&nbsp;&nbsp;&nbsp;已分区表和已分区索引支持与设计和查询标准表和索引相关的所有属性和功能，包括约束、默认值、标识和时间戳值以及触发器。因此，如果要实现位于服务器本地的已分区视图，则可能需要改为实现已分区表。<br />
&nbsp;&nbsp;&nbsp; 决定是否实现分区主要取决于表当前的大小或将来的大小、如何使用表以及对表执行用户查询和维护操作的完善程度。<br />
&nbsp;&nbsp;&nbsp; 通常，如果某个大型表同时满足下列两个条件，则可能适于进行分区：
<ul>
    <li>该表包含（或将包含）以多种不同方式使用的大量数据。 <br />
    <li>不能按预期对表执行查询或更新，或维护开销超过了预定义的维护期。</li>
</ul>
<p>例如，如果对当前月份的数据主要执行 INSERT、UPDATE 和 DELETE 操作，而对以前月份的数据主要执行 SELECT 查询，则如果按月份对表进行分区，表的管理可能要容易些。如果对表的常规维护操作只针对一个数据子集，那么此优点尤为明显。如果该表没有分区，那么就需要对整个数据集执行这些操作，这样就会消耗大量资源。例如，通过分区，可以针对具有只写数据的单个月份执行类似索引重新生成和碎片整理的维护操作，而只读数据仍可用于联机访问。&nbsp;&nbsp; </p>
</fieldset>&nbsp;&nbsp; 正如上面的描述，分区为可以将对数据的操作压力分散到各个分区文件组中，应用程序每次访问的数据只是在某个数据分区上，这样可以相应的提高数据库的性能。<br />
&nbsp;&nbsp; 找个了数据量在200W左右的表，这个表是一个账本类型的表，可以以时间日期作为分区依据列，将200W数据依据月份分配到12个分区上。然后执行业务存储过程进行测试：<br />
&nbsp;&nbsp;&nbsp;
<fieldset><legend>SP</legend>&nbsp; <span lang="EN-US" style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">exec</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">&nbsp;proc_partitiontest<span style="mso-spacerun: yes">&nbsp; </span></span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">@HCompany<span style="color: gray">=</span>N<span style="color: red">'0002'</span><span style="color: gray">,</span>@HOrg<span style="color: gray">=</span>N<span style="color: red">'00000000000000000223'</span><span style="color: gray">,<o:p></o:p></span></span>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">@FiscalYear<span style="color: gray">=</span>N<span style="color: red">'2008'</span><span style="color: gray">,</span>@FiscalPeriod<span style="color: gray">=</span>N<span style="color: red">'01'</span><span style="color: gray">,<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">@HWareHouseID<span style="color: gray">=</span>N<span style="color: red">''</span><span style="color: gray">,</span>@SpeStock<span style="color: gray">=</span>N<span style="color: red">''</span><span style="color: gray">,</span>@ofObject<span style="color: gray">=</span>N<span style="color: red">'' </span><span style="color: gray">,......</span></span></p>
</fieldset><br />
&nbsp;执行结果比较：<br />
&nbsp;&nbsp; 分区前：执行时间52s ，IO cost：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span lang="EN-US" style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">Table</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes"> <span style="color: red">'PartitionAccount'</span><span style="color: gray">.</span> Scan <span style="color: fuchsia">count</span> 2<span style="color: gray">,</span> logical reads 1735<span style="color: gray">,</span> physical reads 0<span style="color: gray">,</span> <span style="color: blue">read</span><span style="color: gray">-</span>ahead reads 0<span style="color: gray">,</span> lob logical reads 0<span style="color: gray">,</span> lob physical reads 0<span style="color: gray">,</span> lob <span style="color: blue">read</span><span style="color: gray">-</span>ahead reads 0.<br />
<o:p>&nbsp; <span style="font-size: 12pt">分区后：执行时间</span>47s ，IO cost：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 10pt; color: blue; font-family: 'Courier New'">Table</span><span style="font-size: 10pt; font-family: 'Courier New'"> <span style="color: red"><span style="color: red">'PartitionAccount'</span></span><span style="color: gray">.</span> Scan <span style="color: fuchsia">count</span> 2<span style="color: gray">,</span> logical reads 76<span style="color: gray">,</span> physical reads 0<span style="color: gray">,</span> <span style="color: blue">read</span><span style="color: gray">-</span>ahead reads 0<span style="color: gray">,</span> lob logical reads 0<span style="color: gray">,</span> lob physical reads 0<span style="color: gray">,</span> lob <span style="color: blue">read</span><span style="color: gray">-</span>ahead reads 0.<br />
&nbsp;<span style="font-size: 10.5pt; font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 11.0pt">对性能提高很一般，是数据量较少的原因么？还是查询应用分区键不太合理？因为一些原因，这个</span><span lang="EN-US" style="font-size: 10.5pt; font-family: 'Calibri','sans-serif'; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-size: 11.0pt">sp</span><span style="font-size: 10.5pt; font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 11.0pt">的具体写法不能贴出，请各位朋友谅解。在这里，请朋友们谈谈分区的关键，谢谢。</span></span></o:p></span>
  <img src ="http://www.cnblogs.com/tianqing/aggbug/1245036.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42976/" target="_blank">[新闻]亚马逊EC2云计算计划支持Windows操作系统</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>菜鸟学sql，Oracle数据库结构比较</title><link>http://www.cnblogs.com/tianqing/archive/2008/06/25/1229419.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Wed, 25 Jun 2008 02:37:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/06/25/1229419.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1229419.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/06/25/1229419.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1229419.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1229419.html</trackback:ping><description><![CDATA[&nbsp;&nbsp; 这几天，正好做oracle下数据库结构比较，比较具体详细差异，例如：2个库具体有那些表不同，不同在什么地方，主键、长度、类型......,要求是用一句sql实现，对于我这个sql菜鸟来说，的确是个挑战。好在有个SQL Server例子可以借鉴。先贴一下oracle下的sql
<div class="cnblogs_code"><span style="color: #008080">&nbsp;1</span>&nbsp;<span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;2</span>&nbsp;<span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;3</span>&nbsp;<span style="color: #008080">--</span><span style="color: #008080">------------------------------------------------------------------------------------</span><span style="color: #008080"><br />
</span><span style="color: #008080">&nbsp;4</span>&nbsp;<span style="color: #008080">--</span><span style="color: #008080">oracle数据库帐套比较，</span><span style="color: #008080"><br />
</span><span style="color: #008080">&nbsp;5</span>&nbsp;<span style="color: #008080">--</span><span style="color: #008080">在本例中，databaseA数据库，</span><span style="color: #008080"><br />
</span><span style="color: #008080">&nbsp;6</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008080">--</span><span style="color: #008080">databaseB是数据库。</span><span style="color: #008080"><br />
</span><span style="color: #008080">&nbsp;7</span>&nbsp;<span style="color: #008080">--</span><span style="color: #008080">在实际的运行过程中，请依据需要修改本sql</span><span style="color: #008080"><br />
</span><span style="color: #008080">&nbsp;8</span>&nbsp;<span style="color: #008080">--</span><span style="color: #008080">------------------------------------------------------------------------------------</span><span style="color: #008080"><br />
</span><span style="color: #008080">&nbsp;9</span>&nbsp;<span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;(</span><span style="color: #ff00ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.表名1&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;b.序号</span><span style="color: #808080">=</span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">库1缺少表：</span><span style="color: #ff0000">'</span><span style="color: #808080">||</span><span style="color: #000000">b.表名2<br />
</span><span style="color: #008080">10</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;b.表名2&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;a.序号</span><span style="color: #808080">=</span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">库2缺少表:</span><span style="color: #ff0000">'</span><span style="color: #808080">||</span><span style="color: #000000">a.表名1<br />
</span><span style="color: #008080">11</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.字段名&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">exists</span><span style="color: #000000">(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;</span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;table_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;表名1&nbsp;&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;DBA_TAB_COLUMNS&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;</span><span style="color: #ff00ff">upper</span><span style="color: #000000">(DBA_TAB_COLUMNS.owner)&nbsp;</span><span style="color: #808080">=</span><span style="color: #ff00ff">upper</span><span style="color: #000000">(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">databaseB</span><span style="color: #ff0000">'</span><span style="color: #000000">))&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;表名1</span><span style="color: #808080">=</span><span style="color: #000000">b.表名2)&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">库1&nbsp;[</span><span style="color: #ff0000">'</span><span style="color: #808080">||</span><span style="color: #000000">b.表名2</span><span style="color: #808080">||</span><span style="color: #ff0000">'</span><span style="color: #ff0000">]&nbsp;缺少字段：</span><span style="color: #ff0000">'</span><span style="color: #808080">||</span><span style="color: #000000">b.字段名<br />
</span><span style="color: #008080">12</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;b.字段名&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">exists</span><span style="color: #000000">(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;</span><span style="font-weight: bold; color: #800000">1</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;table_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;表名2&nbsp;&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;DBA_TAB_COLUMNS&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;</span><span style="color: #ff00ff">upper</span><span style="color: #000000">(DBA_TAB_COLUMNS.owner)&nbsp;</span><span style="color: #808080">=</span><span style="color: #ff00ff">upper</span><span style="color: #000000">(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">databaseA</span><span style="color: #ff0000">'</span><span style="color: #000000">))&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;表名2</span><span style="color: #808080">=</span><span style="color: #000000">a.表名1)&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">库2&nbsp;[</span><span style="color: #ff0000">'</span><span style="color: #808080">||</span><span style="color: #000000">a.表名1</span><span style="color: #808080">||</span><span style="color: #ff0000">'</span><span style="color: #ff0000">]&nbsp;缺少字段：</span><span style="color: #ff0000">'</span><span style="color: #808080">||</span><span style="color: #000000">a.字段名<br />
</span><span style="color: #008080">13</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.主键</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.主键&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">主键不同</span><span style="color: #ff0000">'</span><span style="color: #000000"><br />
</span><span style="color: #008080">14</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.类型</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.类型&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">类型不同</span><span style="color: #ff0000">'</span><span style="color: #000000"><br />
</span><span style="color: #008080">15</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.字段长度</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.字段长度&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">字段长度不同</span><span style="color: #ff0000">'</span><span style="color: #000000"><br />
</span><span style="color: #008080">16</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.精度</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.精度&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">精度不同</span><span style="color: #ff0000">'</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">17</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.小数位</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.小数位&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">小数位不同</span><span style="color: #ff0000">'</span><span style="color: #000000"><br />
</span><span style="color: #008080">18</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">when</span><span style="color: #000000">&nbsp;a.允许空</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.允许空&nbsp;</span><span style="color: #0000ff">then</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">允许空不同</span><span style="color: #ff0000">'</span><span style="color: #000000"><br />
</span><span style="color: #008080">19</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">''</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">end</span><span style="color: #000000">)&nbsp;result,a.</span><span style="color: #808080">*</span><span style="color: #000000">,b.</span><span style="color: #808080">*</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">20</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;a.table_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;表名1,&nbsp;a.column_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;字段名,b.constraint_type&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;主键,&nbsp;a.data_type&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;类型,column_id&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;序号,&nbsp;a.data_length&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;字段长度,&nbsp;a.data_precision&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;精度,&nbsp;&nbsp;a.data_scale&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;小数位,&nbsp;a.nullable&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;允许空&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">21</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;all_tab_columns&nbsp;a&nbsp;</span><span style="color: #808080">left</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">join</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;d.constraint_type,e.column_name,e.table_name&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;all_constraints&nbsp;d,all_cons_columns&nbsp;e<br />
</span><span style="color: #008080">22</span>&nbsp;<span style="color: #000000">&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;&nbsp;d.owner&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.owner&nbsp;&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;d.table_name&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.table_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000"><br />
</span><span style="color: #008080">23</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;d.constraint_name&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.constraint_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;d.constraint_type&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">P</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;b&nbsp;</span><span style="color: #0000ff">on</span><span style="color: #000000">&nbsp;a.COLUMN_NAME&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;b.column_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;a.TABLE_NAME&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;b.table_name<br />
</span><span style="color: #008080">24</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;&nbsp;a.owner&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff00ff">upper</span><span style="color: #000000">(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">databaseB</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">order</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">by</span><span style="color: #000000">&nbsp;表名1&nbsp;</span><span style="color: #0000ff">asc</span><span style="color: #000000">)&nbsp;a<br />
</span><span style="color: #008080">25</span>&nbsp;<span style="color: #000000"><br />
</span><span style="color: #008080">26</span>&nbsp;<span style="color: #0000ff">full</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">join</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;a.table_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;表名2,&nbsp;a.column_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;字段名,b.constraint_type&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;主键,&nbsp;a.data_type&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;类型,column_id&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;序号,&nbsp;a.data_length&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;字段长度,&nbsp;a.data_precision&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;精度,&nbsp;&nbsp;a.data_scale&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;小数位,&nbsp;a.nullable&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;允许空&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">27</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;all_tab_columns&nbsp;a&nbsp;</span><span style="color: #808080">left</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">join</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;d.constraint_type,e.column_name,e.table_name&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;all_constraints&nbsp;d,all_cons_columns&nbsp;e<br />
</span><span style="color: #008080">28</span>&nbsp;<span style="color: #000000">&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;&nbsp;d.owner&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.owner&nbsp;&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;d.table_name&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.table_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000"><br />
</span><span style="color: #008080">29</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;d.constraint_name&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.constraint_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;d.constraint_type&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">P</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;b&nbsp;</span><span style="color: #0000ff">on</span><span style="color: #000000">&nbsp;a.COLUMN_NAME&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;b.column_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;a.TABLE_NAME&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;b.table_name<br />
</span><span style="color: #008080">30</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;&nbsp;a.owner&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff00ff">upper</span><span style="color: #000000">(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">databaseA</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">order</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">by</span><span style="color: #000000">&nbsp;表名2&nbsp;</span><span style="color: #0000ff">asc</span><span style="color: #000000">)&nbsp;b<br />
</span><span style="color: #008080">31</span>&nbsp;<span style="color: #0000ff">on</span><span style="color: #000000">&nbsp;a.表名1</span><span style="color: #808080">=</span><span style="color: #000000">b.表名2&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;a.字段名</span><span style="color: #808080">=</span><span style="color: #000000">b.字段名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">32</span>&nbsp;<span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;&nbsp;a.表名1&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;a.字段名&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;b.表名2&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;b.字段名&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;a.类型</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.类型&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;a.字段长度</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.字段长度&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;a.精度</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.精度&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;a.小数位</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.小数位&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;a.允许空</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.允许空&nbsp;</span><span style="color: #808080">or</span><span style="color: #000000">&nbsp;a.主键</span><span style="color: #808080">&lt;&gt;</span><span style="color: #000000">b.主键<br />
</span><span style="color: #008080">33</span>&nbsp;<span style="color: #0000ff">order</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">by</span><span style="color: #000000">&nbsp;nvl(a.表名1,b.表名2),nvl(a.序号,b.序号)</span></div>
<br />
执行结果显示的差异信息比较详细。可以依据这个来修改数据库，比较方便。<br />
现在分析下这句sq的语法。<br />
1.将两个数据库oracle叫schema下的所有表结构select出来，即：
<fieldset><legend>所有表结构</legend><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;a.table_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;表名1,&nbsp;a.column_name&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;字段名,b.constraint_type&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;主键,&nbsp;a.data_type&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;类型,column_id&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;序号,&nbsp;a.data_length&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;字段长度,&nbsp;a.data_precision&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;精度,&nbsp;&nbsp;a.data_scale&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;小数位,&nbsp;a.nullable&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;允许空&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;all_tab_columns&nbsp;a&nbsp;</span><span style="color: #808080">left</span><span style="color: #000000">&nbsp;</span><span style="color: #808080">join</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">select</span><span style="color: #000000">&nbsp;d.constraint_type,e.column_name,e.table_name&nbsp;</span><span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;all_constraints&nbsp;d,all_cons_columns&nbsp;e<br />
</span>&nbsp;<span style="color: #000000">&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;&nbsp;d.owner&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.owner&nbsp;&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;d.table_name&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.table_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000"><br />
</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;d.constraint_name&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;&nbsp;e.constraint_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;d.constraint_type&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff0000">'</span><span style="color: #ff0000">P</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;b&nbsp;</span><span style="color: #0000ff">on</span><span style="color: #000000">&nbsp;a.COLUMN_NAME&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;b.column_name&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;a.TABLE_NAME&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;b.table_name<br />
</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">where</span><span style="color: #000000">&nbsp;&nbsp;a.owner&nbsp;&nbsp;</span><span style="color: #808080">=</span><span style="color: #000000">&nbsp;</span><span style="color: #ff00ff">upper</span><span style="color: #000000">(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">databaseB</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;</span><span style="color: #0000ff">order</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">by</span><span style="color: #000000">&nbsp;表名1&nbsp;</span><span style="color: #0000ff">asc</span></fieldset>通过上述sql就可以将某个数据库下的表结构select出来，通过left join 关联列的主键。<br />
2. 将要比较的两个库的表结构用full join 关联起来。<br />
3. 同在用case来比较具体不同信息。然后在加上where条件。<br />
<br />
综述，比较oracle中，2个数据库的表结构基本就用上述sql比较了，效率有些慢，朋友们有好的建议可以谈谈。谢谢。<br />
 <img src ="http://www.cnblogs.com/tianqing/aggbug/1229419.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42975/" target="_blank">[新闻]鲍尔默失望变希望 幸亏当初未收购雅虎</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>自己对环境和社会的一些感悟</title><link>http://www.cnblogs.com/tianqing/archive/2008/06/23/1228129.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Mon, 23 Jun 2008 05:40:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/06/23/1228129.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1228129.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/06/23/1228129.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1228129.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1228129.html</trackback:ping><description><![CDATA[&nbsp;&nbsp; 最近，我一值在考虑一些问题，想想自己当前的境况，想想自己的未来。感到一丝惆怅的同时，也有一些顿悟。<br />
&nbsp;&nbsp; 从学校里，我们便被灌输：你要适应社会，不要让社会来适应你。当时考虑这些话是很对的，的确，当你刚步入社会，你的个人能力和社会经验是少的可怜，也许你有很多个性，很多理想，但在现实面前你不得不低头而放弃。那时，我明白了可以有机会去追求自己的理想是件多么快乐的事情。随着你慢慢适应社会，你的能力和社会经验得到提升，你从一个学生转变为一个职业人，你开始慢慢总结你自己，想一些事情，想自己的未来。你发现你的刺慢慢被磨平，你的理想离你越来越远，而你在做的还是不断的改变自己适应环境。这样到底对还是不对，有没有意义......一个非常矛盾的问题。<br />
&nbsp;&nbsp; 当你很弱小时，你不得不在一些事情上低头，强制自己干一些自己不喜欢的事情，这也就应了一句话：天将降大任于斯人也，必先苦其心志，劳其筋骨，饿其体肤，行拂乱其所为......,对啊。当你变强时，你提高了自己，但仍旧继续着不喜欢的事情，偶尔还有些郁郁不得志的感觉。这时，社会的舆论又会告诉你：不要浮躁，要塌下心干一些事情。你所在的环境——企业一边在培养你的忠诚，一边在剥削着你的剩余价值，这时的你又该如何去选择......<br />
&nbsp;&nbsp;&nbsp;程序员，是一个即充满乐趣又充斥的痛苦的职业，痛并快乐着。我们成就在自己的代码、设计思想里面，为了更强，跟得上技术的更新，不断的学习，不断的战胜自己。然而，此消彼长，这样的生活间接降低了我们生活的质量，有限的闲暇时间，休息时间......，努力提高自己的同时而放弃了很多很多，例如：爱情、友情、EQ。你会经常问自己这到底值不值？答案是肯定的:值。因为我们已经付出了努力，努力就会有回报。但你自己不想改变些什么么？<br />
&nbsp;&nbsp; 难道你不想拥有高质量的，快乐而轻松的的生活吗？是啊，做梦都想，所以才不知疲倦的努力。其实，我们应该更具有一些魄力，重新找回自己的理想，做自己的主人。当我们在努力适应了一个发现自己不喜欢的环境后，我们可不可以换一个自己喜欢的环境呢？怎么不可以呢？也许有人会说你对企业不忠诚，但是他们怎么不说企业不善于培养员工的企业忠诚度呢？严介和：&#8220;一流企业家做人不做事，二流企业家做人又做事，三流企业家不做人只做事，一流企业做文化，二流企业做品牌，三流企业做项目。这是一句至理名言，很有道理。<br />
&nbsp;&nbsp;&nbsp; 所以，我们是否应该清晰的看好当前的环境，而做出自己正确的选择呢？在这个社会找到更适应自己的环境呢？我个人感觉，我们在自我努力的同时应该更好的实现自己的价值。走自己的路让别人说去吧。<br />
&nbsp;&nbsp; 希望作为程序员的战友们，都能找到自己的方向，自己美好的未来。<br />
&nbsp; 
<img src ="http://www.cnblogs.com/tianqing/aggbug/1228129.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42974/" target="_blank">[新闻]微软12月举办硬件工程大会 Windows7将首次亮相</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>SQL Server2005探索之—— 利用SQL Server2005提供的namespace 编程</title><link>http://www.cnblogs.com/tianqing/archive/2008/05/24/1206477.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Sat, 24 May 2008 09:01:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/05/24/1206477.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1206477.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/05/24/1206477.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1206477.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1206477.html</trackback:ping><description><![CDATA[&nbsp;&nbsp; 最近，在探索SQL Server2005的新特性,例如，SSIS，Replication.....,利用SSIS（<span lang="EN-US" style="font-size: 10.5pt; font-family: 'Calibri','sans-serif'; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Microsoft SQL Server Integration Services </span>）将Oracle数据库整体迁移到SQL Server2005中（<img alt="" src="http://www.cnblogs.com/Emoticons/tusiji/203330839.gif" />），Replication 实现了多个数据库服务器之间的数据同步，间接的提高的数据库的性能。相信朋友们一定很熟悉，在这里就不再赘述了。那么，今天和朋友们一起讨论讨论，利用SQL Server2005提供的namespace 编程<img alt="" src="http://www.cnblogs.com/Emoticons/tusiji/202939796.gif" /><br />
<br />
&nbsp;&nbsp;&nbsp;<font color="#003366"> <span style="color: #000000">在SQL Server2005 的使用当中，从2000起便提供了Script 支持，即</span>：<br />
<br />
</font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp; <img style="width: 500px; height: 313px" height="313" alt="" src="http://www.cnblogs.com/images/cnblogs_com/tianqing/SQLScripte.JPG" width="500" border="0" /><br />
&nbsp;&nbsp; 这种脚本支持很方便，但需要你去选择，再去执行，time and time again,so boring.....，想个办法用程序实现。<br />
&nbsp;&nbsp; 在TechNet searcher 一下，找到了Table,Index..... 这些class，ok，接着找到SQLServer2005联机丛书上有相关介绍:<br />
&nbsp;&nbsp;&nbsp;
<fieldset style="font-size: 10pt"><legend>Here</legend>
<p>The <strong>Index</strong> object represents a Microsoft&nbsp;SQL Server index.
<p><strong>Namespace:</strong> Microsoft.SqlServer.Management.Smo<br />
<strong>Assembly:</strong> Microsoft.SqlServer.Smo (in microsoft.sqlserver.smo.dll)</p>
</fieldset>&nbsp; 仔细看了看Index的Methods，找到了script（）方法，对，就这个方法。Now, coding......<br />
&nbsp;
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080">&nbsp;1</span><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;indexScript(string servername,string username,string userpwd,string dbname,string tablename,string )schemaname<br />
</span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img id="Codehighlighter1_35_1170_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_35_1170_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_35_1170_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_35_1170_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_35_1170_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_35_1170_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_35_1170_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_35_1170_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_35_1170_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />
</span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_65_1170_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_65_1170_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_65_1170_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_65_1170_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_65_1170_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_65_1170_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_65_1170_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_65_1170_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_65_1170_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Server&nbsp;server&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Server(</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ServerConnection(servername,username,&nbsp;userpwd));<br />
</span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatabaseCollection&nbsp;dbcollection&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;server.Databases;<br />
</span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Database&nbsp;db&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dbcollection[dbname];<br />
</span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TableCollection&nbsp;tabCollection&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;db.Tables;<br />
</span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Table&nbsp;tab&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tabCollection[tablename,&nbsp;schemaname];<br />
</span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IndexCollection&nbsp;indexCollection&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;tab.Indexes;<br />
</span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" /><br />
</span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;h&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;&nbsp;h&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;indexCollection.Count;&nbsp;h</span><span style="color: #000000">++</span><span style="color: #000000">)<br />
</span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_602_1050_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_602_1050_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_602_1050_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_602_1050_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_602_1050_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_602_1050_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_602_1050_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_602_1050_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_602_1050_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringCollection&nbsp;sc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;indexCollection[h].Script();<br />
</span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringBuilder&nbsp;stringbuilder&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StringBuilder();<br />
</span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;sc.Count;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />
</span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_860_953_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_860_953_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_860_953_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_860_953_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_860_953_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_860_953_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_860_953_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_860_953_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_860_953_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stringbuilder.Append(sc[i].ToString()&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
</span><span style="color: #008080">19</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">20</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" /><br />
</span><span style="color: #008080">21</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(stringbuilder.ToString());<br />
</span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">23</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000">&nbsp;(Exception&nbsp;ex)<br />
</span><span style="color: #008080">24</span><span style="color: #000000"><img id="Codehighlighter1_1096_1160_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1096_1160_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1096_1160_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1096_1160_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1096_1160_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1096_1160_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1096_1160_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1096_1160_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span id="Codehighlighter1_1096_1160_Open_Text"><span style="color: #000000">{<br />
</span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000ff">throw</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Exception(ex.Message);<br />
</span><span style="color: #008080">26</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span><span style="color: #000000"><br />
</span><span style="color: #008080">27</span><span style="color: #000000"><img alt="" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></span></span></div>
&nbsp;&nbsp; 这样就可以将所有 index的script 显示出来，然后你可以再操纵这些script了，例如导称sql文件再执行。至于其他object都可以使用上面的方法。<br />
&nbsp;&nbsp; 上面这个方法只能用于rebuilder数据库对象，因为script():Generates a Transact-SQL script that can be used to re-create the index.<br />
其他select、alter脚本估计也可以用程序实现，我正在找......,找到了再补充，呵呵。<br />
&nbsp;&nbsp; 
 <img src ="http://www.cnblogs.com/tianqing/aggbug/1206477.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42973/" target="_blank">[新闻]电脑程序与12位真人聊天 “艾尔博特”骗过3人</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>SQL Server 数据类型学习</title><link>http://www.cnblogs.com/tianqing/archive/2008/04/17/1158176.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Thu, 17 Apr 2008 07:29:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/04/17/1158176.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1158176.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/04/17/1158176.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1158176.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1158176.html</trackback:ping><description><![CDATA[&nbsp; 这些天，需要由Oracle移植到SQL Server，用到了Microsoft 的<font face="Verdana">Microsoft SQL Server Migration Assistant 2005 for Oracle</font>，用到了数据类型，所以对SQL Server 的数据类型来了个全面的学习，先总结几个关键点，于朋友们分享
<fieldset><legend><strong><span style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">The difference between char and nchar</span></strong></legend>&nbsp; <span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">CHAR</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">是固定长度的字节，</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">VARCHAR</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">是可变长度的字节，</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">NCHAR</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">是</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">UNICODE</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">编码的固定字符长度。</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"> &nbsp; <br />
&nbsp; </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">如：</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">12345 &nbsp; &nbsp; </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">在</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">CHAR(6)</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">存储为</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">123456</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">加一个空格，共</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">6</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">个字节。</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">中国</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"> &nbsp; &nbsp; &nbsp; </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">在</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">CHAR(6)</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">存储为中国加两个空格，共</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">6</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">个字节。</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 12345 &nbsp; &nbsp; </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">在</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">VARCHAR(6)</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">存储为</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">123456</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">，共</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">5</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">个字节。</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">中国</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"> &nbsp; &nbsp; &nbsp; </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">在</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">VARCHAR(6)</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">存储为中国，共</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">4</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">个字节。</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"> &nbsp; <br />
&nbsp; NCHAR(6)</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">对汉字和半角字符处理时一样的</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">, </span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">而</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">NCHAR</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">以</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">char</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">类似，采用</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'">Unicode</span><span style="font-size: 9pt; font-family: 宋体; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma">标准字符集，每个字符占用两个字节空间。</span><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'"><o:p></o:p></span></fieldset>
<fieldset><legend><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-size: 9pt; font-family: 'Tahoma','sans-serif'; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">The difference between Char and Varchar</span></strong></legend><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char</span><span style="font-size: 9pt; font-family: 宋体">数据类型用来存储指定长度的定长非统一编码型的数据。当定义一列为此类型时，你必须指定列长。当你总能知道要存储的数据的长度时，此数据类型很有用。例如，当你按邮政编码加</span><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">4</span><span style="font-size: 9pt; font-family: 宋体">个字符格式来存储数据时，你知道总要用到</span><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">10</span><span style="font-size: 9pt; font-family: 宋体">个字符。此数据类型的列宽最大为</span><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">8000 </span><span style="font-size: 9pt; font-family: 宋体">个字符</span><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">;</span>
<p style="margin-left: 21pt; text-indent: 9pt; text-align: left" align="left"><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">varchar</span><span style="font-size: 9pt; font-family: 宋体">数据类型，同</span><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">char</span><span style="font-size: 9pt; font-family: 宋体">类型一样，用来存储非统一编码型字符数据。与</span><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">char </span><span style="font-size: 9pt; font-family: 宋体">型不一样，此数据类型为变长。当定义一列为该数据类型时，你要指定该列的最大长度。</span><span style="font-size: 9pt; font-family: 宋体">它与</span><span style="font-size: 9pt; font-family: 'Verdana','sans-serif'">char</span><span style="font-size: 9pt; font-family: 宋体">数据类型最大的区别是，<strong>存储的长度不是列长，而是数据的长度</strong></span></p>
</fieldset>
<fieldset><legend><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-size: 9pt; font-family: 'Verdana','sans-serif'; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi">The difference between Varchar and Nvarchar</span></strong></legend>&nbsp; <strong><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">varchar(n)</span></strong><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"><br />
</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">长度为</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> n </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">个字节的可变长度且非</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> Unicode </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">的字符数据。</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">n </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">必须是一个介于</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> 1 </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">和</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> 8,000 </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">之间的数值。存储大小为输入数据的字节的实际长度，而不是</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> n </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">个字节。</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"><br />
<strong>&nbsp;&nbsp; nvarchar(n)</strong><br />
&nbsp;</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">包含</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> n </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">个字符的可变长度</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> Unicode </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">字符数据。</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">n </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">的值必须介于</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> 1 </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">与</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"> 4,000 </span><span style="font-size: 9pt; color: #333333; font-family: 宋体">之间。字节的存储大小是所输入字符个数的两倍。</span>
<p style="margin-left: 10.5pt; text-indent: 9pt; text-align: left" align="left"><span style="font-size: 9pt; color: #333333; font-family: 宋体">两字段分别有字段值：我和</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">coffee<br />
</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">那么</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">varchar</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">字段占</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">2&#215;2+6=10</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">个字节的存储空间，而</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">nvarchar</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">字段占</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">8&#215;2=16</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">个字节的存储空间。</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'"><br />
</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">如字段值只是英文可选择</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">varchar</span><span style="font-size: 9pt; color: #333333; font-family: 宋体">，而字段值存在较多的双字节（中文、韩文等）字符时用</span><span style="font-size: 9pt; color: #333333; font-family: 'Tahoma','sans-serif'">nvarchar</span></p>
</fieldset><br />
&nbsp;&nbsp; 就这些了，呵呵。 
<img src ="http://www.cnblogs.com/tianqing/aggbug/1158176.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42971/" target="_blank">[新闻]Mozilla发布网页开发工具实验室</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>弱弱的问大侠们个问题</title><link>http://www.cnblogs.com/tianqing/archive/2008/04/10/1146080.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Thu, 10 Apr 2008 01:05:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/04/10/1146080.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1146080.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/04/10/1146080.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1146080.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1146080.html</trackback:ping><description><![CDATA[园子里的朋友们：<br />
&nbsp;&nbsp;&nbsp; 你们好，小弟想问大家个问题，关于个人职业发展与方向的。我现在的公司的部门调整，我以后就负责项目的性能调优，以及程序debug，还有一些维护工作，性能调优占40%，维护的占35%，程序debug占25%，维护其实在走量，学不到什么，差不多在浪费青春，性能调优和debug比较好，我个人比较喜欢设计和 写程序。<br />
&nbsp;&nbsp;&nbsp; 关于性能调优和debug，咨询各位，以后发展怎么样啊？前景如何？谢谢。
 <img src ="http://www.cnblogs.com/tianqing/aggbug/1146080.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42970/" target="_blank">[新闻]经典软件十五年深情回眸</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>what AS and Is are? </title><link>http://www.cnblogs.com/tianqing/archive/2008/03/29/1128783.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Sat, 29 Mar 2008 05:45:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/03/29/1128783.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1128783.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/03/29/1128783.html#Feedback</comments><slash:comments>12</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1128783.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1128783.html</trackback:ping><description><![CDATA[&nbsp; 今天看了AnyTao博客上 -------[你必须知道的.NET] 第一回：恩怨情仇：is和as ,通过MSDN，对As 和Is在C#里的用法来了个深刻的理解，现总结一下，和园子里朋友共享。<br />
&nbsp; 先引用AnyTao的解释：比较好,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<fieldset><legend>Here</legend>is的规则如下：
<ul>
    <li>检查对象类型的兼容性，并返回结果，true或者false；
    <li>不会抛出异常；
    <li>如果对象为null，则返回值永远为false。 </li>
</ul>
<p>as的规则如下： </p>
<ul>
    <li>检查对象类型的兼容性，并返回结果，如果不兼容就返回null；
    <li>不会抛出异常；
    <li>如果结果判断为空，则强制执行类型转换将抛出NullReferenceException异常。 </li>
</ul>
<p>&nbsp;</p>
</fieldset><br />
<hr />
我对&#8220;is/as操作符，提供了更加灵活的类型转型方式，但是as操作符在执行效率上更胜一筹&#8221;不太理解.......<br />
在MSDN上search了一下，<br />
<br />
&nbsp;
<fieldset style="line-height: normal"><legend>As</legend>
<div class="title">as（C# 参考）<!----></div>
<!--content type: DocStudio. Transform: devdiv2mtps.xslt.-->
<div id="mainSection">
<div id="mainBody">
<p>
<p>用于在兼容的引用类型之间执行转换。例如：</p>
<div class="title">
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;s&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;someObject&nbsp;</span><span style="color: #0000ff">as</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">;<br />
<img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(s&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">)<br />
<img id="Codehighlighter1_48_82_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_48_82_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_48_82_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_48_82_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_48_82_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_48_82_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_48_82_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_48_82_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top"  alt="" /></span><span id="Codehighlighter1_48_82_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_48_82_Open_Text"><span style="color: #000000">{<br />
<img src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;someObject&nbsp;is&nbsp;a&nbsp;string.</span><span style="color: #008000"><br />
<img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" /></span><span style="color: #000000">}</span></span></div>
</div>
</div>
</div>
<strong>as</strong> 运算符类似于强制转换操作；但是，如果转换不可行，<strong>as</strong> 会返回 <strong>null</strong> 而不是引发异常。更严格地说，这种形式的表达式<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expression as type<br />
<br />
equal to------&gt;<br />
<br />
<font face="Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expression is type ? (type)expression : (type)null<br />
<br />
<p>只是 <tt>expression</tt> 只被计算一次。</p>
<p>注意，<strong>as</strong> 运算符只执行引用转换和装箱转换。<strong>as</strong> 运算符无法执行其他转换，如用户定义的转换，这类转换应使用 cast 表达式来执行</p>
</font></fieldset>
<fieldset><legend>Is</legend>
<div class="title">is（C# 参考）<!----></div>
<!--content type: DocStudio. Transform: devdiv2mtps.xslt.-->
<div id="mainSection">
<div id="mainBody">
<p>
<p>检查对象是否与给定类型兼容。例如，可以确定对象是否与 <strong>string</strong> 类型兼容，如下所示：</p>
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(obj&nbsp;</span><span style="color: #0000ff">is</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">)<br />
<img id="Codehighlighter1_19_22_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_19_22_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_19_22_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_19_22_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"  alt="" /><img id="Codehighlighter1_19_22_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_19_22_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_19_22_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_19_22_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top"  alt="" /></span><span id="Codehighlighter1_19_22_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_19_22_Open_Text"><span style="color: #000000">{<br />
<img src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div>
</div>
</div>
<p>如果所提供的表达式非空，并且所提供的对象可以强制转换为所提供的类型而不会导致引发异常，则 <strong>is</strong> 表达式的计算结果将是 <strong>true</strong>。</p>
<p>如果已知表达式将始终是 <strong>true</strong> 或始终是 <strong>false</strong>，则 <strong>is</strong> 关键字将导致编译时警告，但是，通常在运行时才计算类型兼容性。</p>
<p>不能重载 <strong>is</strong> 运算符。</p>
<p>请注意，<strong>is</strong> 运算符只考虑引用转换、装箱转换和取消装箱转换。不考虑其他转换，如用户定义的转换。</p>
</fieldset>&nbsp; 现在清晰多了，呵呵。
<img src ="http://www.cnblogs.com/tianqing/aggbug/1128783.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42969/" target="_blank">[新闻]MySpace推自助广告平台MyAds</a><br/><a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻频道</a>&nbsp;<a href="http://space.cnblogs.com/group.htm" target="_blank">小组</a>&nbsp;<a href="http://space.cnblogs.com/q" target="_blank">博问</a>&nbsp;<a href="http://wz.cnblogs.com/" target="_blank">网摘</a>&nbsp;<a href="http://space.cnblogs.com/ing" target="_blank">闪存</a>]]></description></item><item><title>treeview 和数据源绑定</title><link>http://www.cnblogs.com/tianqing/archive/2008/03/12/1101644.html</link><dc:creator>Eric zhou</dc:creator><author>Eric zhou</author><pubDate>Wed, 12 Mar 2008 02:14:00 GMT</pubDate><guid>http://www.cnblogs.com/tianqing/archive/2008/03/12/1101644.html</guid><wfw:comment>http://www.cnblogs.com/tianqing/comments/1101644.html</wfw:comment><comments>http://www.cnblogs.com/tianqing/archive/2008/03/12/1101644.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/tianqing/comments/commentRss/1101644.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tianqing/services/trackbacks/1101644.html</trackback:ping><description><![CDATA[&nbsp; 前几天写了个ASP.NET程序，用到了treeview作为左边菜单，依据用户的角色来初始treeview，比较简单实用，所以现在总结一下，和博友们共享一下。<br />
&nbsp; 首先需要一个关系数据库表结构:就这个结构<br />
<hr />
<br />
<table style="vertical-align: baseline; text-align: center" bordercolor="#99ccff" cellspacing="2" cellpadding="2" width="500" border="0">
    <tbody>
        <tr>
            <td>NodeId</td>
            <td>ModualID</td>
            <td>NodeName</td>
            <td>NodeURL</td>
        </tr>
        <tr>
            <td>1</td>
            <td>&lt;null&gt;</td>
            <td>head1</td>
            <td>URL</td>
        </tr>
        <tr>
            <td>2</td>
            <td>&lt;null&gt;</td>
            <td>head2</td>
            <td>URL</td>
        </tr>
        <tr>
            <td>3</td>
            <td>&lt;null&gt;</td>
            <td>head3</td>
            <td>URL</td>
        </tr>
        <tr>
            <td>4</td>
            <td>1</td>
            <td>head11</td>
            <td>URL</td>
        </tr>
        <tr>
            <td>5</td>
            <td>2</td>
            <td>head21</td>
            <td>URL</td>
        </tr>
        <tr>
            <td>6</td>
            <td>3</td>
            <td>head31</td>
            <td>URL</td>
        </tr>
    </tbody>
</table>
<hr />
<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;inimenu(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;strrole)<br />
<img id="Codehighlighter1_44_140_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_44_140_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_44_140_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_44_140_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_44_140_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_44_140_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_44_140_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_44_140_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_44_140_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_44_140_Open_Text"><span style="color: #000000">{<br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitTree(</span><span style="color: #0000ff">this</span><span style="color: #000000">.TreeView_Menu,&nbsp;Appclass.TreeDataSet(strrole));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">这里Appclass.TreeDataSet(strrole)为通过用户角色strrole来初始绑定treeview对应DataSet</span><span style="color: #008000"><br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;DataSet&nbsp;TreeDataSet(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;Role)<br />
<img id="Codehighlighter1_258_274_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_258_274_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_258_274_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_258_274_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_258_274_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_258_274_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_258_274_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_258_274_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_258_274_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_258_274_Open_Text"><span style="color: #000000">{<br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;<img alt="" src="http://www.cnblogs.com/Images/dot.gif" /><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /><br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: #000000"><br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top" /><br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;InitTree(TreeView&nbsp;treeview,&nbsp;DataSet&nbsp;ds)<br />
<img id="Codehighlighter1_336_971_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_336_971_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_336_971_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_336_971_Closed_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_336_971_Closed_Image" style="display: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_336_971_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_336_971_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_336_971_Open_Text').style.display='inline';" alt="" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_336_971_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span id="Codehighlighter1_336_971_Open_Text"><span style="color: #000000">{<br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;treeview.Nodes.Clear();<br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ds.Relations.Add(</span><span style="color: #800000">"</span><span style="color: #800000">NodeRelation</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;ds.Tables[</span><span style="color: #800080">0</span><span style="color: #000000">].Columns[</span><span style="color: #800000">"</span><span style="color: #800000">NodeId</span><span style="color: #800000">"</span><span style="color: #000000">],&nbsp;ds.Tables[</span><span style="color: #800080">0</span><span style="color: #000000">].Columns[</span><span style="color: #800000">"</span><span style="color: #800000">ModualID</span><span style="color: #800000">"</span><span style="color: #000000">],&nbsp;</span><span style="color: #0000ff">false</span><span style="color: #000000">);<br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" /><br />
<img alt="" src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">foreach</span><span style="color: #000000">&nbsp;(DataRow&nbsp;dbRow&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;ds.Tables[</span><span style="color: #800080">0</span><span style="color: #000000">].Rows)<br />
<img id="Codehighlighter1_563_892_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_563_892_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_563_892_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_563_892_Closed_Text').style.display='inline';" alt="" src="http: