﻿<?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>BlogJava-爪哇一角-文章分类-SQL Server</title><link>http://www.blogjava.net/ocean07000814/category/37335.html</link><description>共同探讨STRUTS#HIBERNATE#SPRING#EJB等技术</description><language>zh-cn</language><lastBuildDate>Thu, 04 Feb 2010 10:56:51 GMT</lastBuildDate><pubDate>Thu, 04 Feb 2010 10:56:51 GMT</pubDate><ttl>60</ttl><item><title>Sql server的TOP函数 与oracle的rownum及MySQL中的limit</title><link>http://www.blogjava.net/ocean07000814/articles/311804.html</link><dc:creator>非洲小白脸</dc:creator><author>非洲小白脸</author><pubDate>Wed, 03 Feb 2010 06:20:00 GMT</pubDate><guid>http://www.blogjava.net/ocean07000814/articles/311804.html</guid><wfw:comment>http://www.blogjava.net/ocean07000814/comments/311804.html</wfw:comment><comments>http://www.blogjava.net/ocean07000814/articles/311804.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ocean07000814/comments/commentRss/311804.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ocean07000814/services/trackbacks/311804.html</trackback:ping><description><![CDATA[<div class="bct fc11 nbw-blog ztag js-fs2">
<p style="text-indent: 2em;">Sql server:</p>
<p style="text-indent: 2em;">//前5行</p>
<p style="text-indent: 2em;">select top 5 * from table</p>
<p style="text-indent: 2em;">//查询第m条到第n条记录 </p>
<p style="text-indent: 2em;">Select
top (n-(m-1)) * from [tablename] where [parimary key] not in(select top
(m-1) [parimary key] from [tablename] order by [排序字段及排序方法]) order by
[排序字段及排序方法];</p>
<p style="text-indent: 2em;">oracle:</p>
<p style="text-indent: 2em;">//前5行</p>
<p style="text-indent: 2em;">select * from table where rownum &lt;= 5;</p>
<p style="text-indent: 2em;">//第5到10行</p>
<p style="text-indent: 2em;">select * from table where rownum&lt;10 </p>
<p style="text-indent: 2em;">minus </p>
<p style="text-indent: 2em;">select * from table where rownum&lt;4;</p>
<p style="text-indent: 2em;">类似可以实现分页功能</p>
<p style="text-indent: 2em;">MySQL</p>
<p style="text-indent: 2em;">实现Top N及M至N段的记录查询</p>
<p style="text-indent: 2em;">我们可以利用MySQL中SELECT支持的一个子句——LIMIT——来完成这项功能。</p>
<p style="text-indent: 2em;">LIMIT可以实现top N查询，也可以实现M至N（某一段）的记录查询，具体语法如下：</p>
<p style="text-indent: 2em;">SELECT * FROM MYTABLE</p>
<p style="text-indent: 2em;">ORDER BY AFIELD</p>
<p style="text-indent: 2em;">LIMIT offset, recnum</p>
<p style="text-indent: 2em;">其中offset为从第几条（M+1）记录开始，recnum为返回的记录条数。例：</p>
<p style="text-indent: 2em;">select * from mytable</p>
<p style="text-indent: 2em;">order by afield</p>
<p style="text-indent: 2em;">limit 2, 5</p>
<p style="text-indent: 2em;">即意为从第3条记录开始的5条记录。</p>
</div>
<img src ="http://www.blogjava.net/ocean07000814/aggbug/311804.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ocean07000814/" target="_blank">非洲小白脸</a> 2010-02-03 14:20 <a href="http://www.blogjava.net/ocean07000814/articles/311804.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL Server索引</title><link>http://www.blogjava.net/ocean07000814/articles/252297.html</link><dc:creator>非洲小白脸</dc:creator><author>非洲小白脸</author><pubDate>Thu, 22 Jan 2009 01:10:00 GMT</pubDate><guid>http://www.blogjava.net/ocean07000814/articles/252297.html</guid><wfw:comment>http://www.blogjava.net/ocean07000814/comments/252297.html</wfw:comment><comments>http://www.blogjava.net/ocean07000814/articles/252297.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ocean07000814/comments/commentRss/252297.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ocean07000814/services/trackbacks/252297.html</trackback:ping><description><![CDATA[1、评估索引本身的占用空间，当索引相对于其数据本身过大可能会无明显作用。这种情况体现在：表很小，索引列过多，索引碎片过多。当索引在select中不起作用时，你还必须在insert和update、delete这些操作中去维护这些不起作用的数据。<br />
2、In语句不一定不能使用索引，where id in(1,2)和where id =1 or id=2是等效的，这里的in和not
in的性能是相同的。而不能使用索引的原因是嵌套查询： where id in(select 1 union select 2).<br />
3、解除嵌套查询无法利用索引的办法是用exists子查询，select * from tb1 a where exists(select 1
from tb2 where id=a.id)。而exists和not
exists的性能和tb1的数据量无关，他们的性能差别在于tb2中的数据量。<br />
4、Like子句可以利用索引，所以尽可能少用left，right和substring函数。 <br />
5、函数不能使用索引，比如convert(varchar(7),date,120)='2008-06'，或者datediff函数、甚至和常量的加减乘除运算等，正确的做法是用比较符号或者尽可能把datediff之类的函数放到等号右边。<br />
6、不用担心隐式转换，它总是转换等号右边的。比如 where id='2' 和where id=2是等效的。<br />
7、聚集索引的查询性能好于非聚集索引，但是维护代价很大，对于他的数据改变会引起整行数据的物理位置移动。同时聚集索引还要为非聚集索引提供索引服务，所以尽量不用过大的列或过多的列作聚集索引。<br />
8、聚集索引可以极大优化大于，小于，group by和order by以及join语句的查询性能。<br />
9、一张表只能由一个聚集索引。<br />
10、唯一索引有助于查询优化。<br />
11、联合索引的第一列可以单独使用，其他的索引列在单独的where子句中不起作用。 <br />
12、索引的升序降序对order by子句的影响很大。<br />
13、符合特定条件的计算列也可以创建索引。<br />
<br />
<img src ="http://www.blogjava.net/ocean07000814/aggbug/252297.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ocean07000814/" target="_blank">非洲小白脸</a> 2009-01-22 09:10 <a href="http://www.blogjava.net/ocean07000814/articles/252297.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL Server 区分大小写设置</title><link>http://www.blogjava.net/ocean07000814/articles/252248.html</link><dc:creator>非洲小白脸</dc:creator><author>非洲小白脸</author><pubDate>Wed, 21 Jan 2009 09:24:00 GMT</pubDate><guid>http://www.blogjava.net/ocean07000814/articles/252248.html</guid><wfw:comment>http://www.blogjava.net/ocean07000814/comments/252248.html</wfw:comment><comments>http://www.blogjava.net/ocean07000814/articles/252248.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ocean07000814/comments/commentRss/252248.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ocean07000814/services/trackbacks/252248.html</trackback:ping><description><![CDATA[1.停止服务器。<br />
2.到SQl安装目录....../Tools/Binn/rebuildm.exe&nbsp;&nbsp; 运行，就可以更改字符集,排序方式,及大小写敏感。<br />
<br />
Case Sensitive 区分大小写<br />
<br />
如果数据库区分大小写，当搜索文本数据时，必须用正确的大小写字母组合构造搜索条件。例如，如果搜索名字"Smith"，则不能使用搜索条件"=smith"或"=SMITH"。<br />
<img src ="http://www.blogjava.net/ocean07000814/aggbug/252248.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ocean07000814/" target="_blank">非洲小白脸</a> 2009-01-21 17:24 <a href="http://www.blogjava.net/ocean07000814/articles/252248.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>