简体   繁体   English

SQL Server 2005新手查询

[英]Sql Server 2005 novice query

I am very beginner in SQL Server 2005 and I am learning it from online tutorial, here is some of my question: 我是SQL Server 2005的初学者,我正在在线教程中学习它,这是我的一些问题:

1: What is the difference between Select * from XYZ and Select ALL * from XYZ. 1:从XYZ中选择*和从XYZ中选择所有*有什么区别?

2: The purpose of Clustered index is like to make the search easier by physically sorting the table [as far as I kknow :-)]. 2:聚集索引的目的是通过对表进行物理排序来简化搜索(据我所知:-)。 Let say if have primary column on a table than is it good to create a clustered index on the table? 假设表上有主列是否比在表上创建聚簇索引好? because we have already a column which is sorted. 因为我们已经有一个已排序的列。

3: Why we can create 1 Clustered Index + 249 Nonclustered Index = 250 Index on a table? 3:为什么我们可以在表上创建1个聚集索引+ 249个非聚集索引= 250个索引? I understand the requirement of 1 clustered index. 我了解1个聚集索引的要求。 But why 249?? 但是为什么是249? Why not more than 249? 为什么不超过249?

  1. No difference SELECT ALL is the default as opposed to SELECT DISTINCT SELECT DISTINCT相反, SELECT DISTINCT SELECT ALL是默认设置

  2. Opinion varies. 意见各不相同。 For performance reasons Clustered indexes should ideally be small, stable, unique, and monotonically increasing. 出于性能原因,理想情况下,聚簇索引应该较小,稳定,唯一且单调递增。 Primary keys should also be stable and unique so there is an obvious fit there. 主键也应该是稳定且唯一的,因此很明显。 However clustered indexes are well suited for range queries. 但是,聚簇索引非常适合范围查询。 Looking up individual records by PK can perform well if the PK is nonclustered so some authors suggest not "wasting" the clustered index on the PK. 如果PK是非集群的,则按PK查找单个记录的效果很好,因此一些作者建议不要“浪费” PK上的聚集索引。

  3. In SQL Server 2008 you can create up to 999 NCIs on a table. 在SQL Server 2008中,一个表上最多可以创建999个NCI。 I can't imagine ever doing so but I think the limit was raised as potentially with "filtered indexes" there might be a viable case for this many. 我无法想象曾经这样做过,但我认为限制已提高,因为“筛选索引”可能会为许多人提供可行的解决方案。 Indexes add a cost to data modification operations though as the changes need to be propagated in multiple places so I would imagine it would only be largely read only (eg reporting) databases that ever achieve even double figures of non clustered non filtered indexes. 索引增加了数据修改操作的成本,因为更改需要在多个位置传播,因此我想它只会在很大程度上是只读的(例如报告)数据库,即使非聚集非过滤索引甚至达到两倍。

For 3: 对于3:

Everytime when you insert/delete record in the table ALL indexes must be updated. 每次在表中插入/删除记录时,所有索引都必须更新。 If you will have too many indexes it takes too long time. 如果索引过多,则需要花费很长时间。

If your table have more then 5-6 indexes I think you need take the time and check yourself. 如果您的表有5-6个以上的索引,我认为您需要花一些时间检查一下自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM