天下第一菜题,各位ggjj得帮我!

Only_I 2001-10-22 08:09:59
1、索引到底是什么?创建索引,数据库到底是怎么做的?得到一个新的‘表’吗?与定义的主键、外键有何区别?
2、聚集与非聚集有什么区别?我搞不懂它两个在说什么。
3、如果我的数据在添加进库里的一段日子内需要处理(既要经常检索出来),过了这段日子,我就基本不用它了(但不能删除),那我的查询操作该怎么做才能快一点儿(数据量比较大)?


ggjj们,我刚学数据库,给点帮助吧!
进来的朋友也帮我up一下!小弟先谢过了!
...全文
125 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
昵称被占用了 2001-10-22
  • 打赏
  • 举报
回复
外键建议看这个帖子:
http://www.csdn.net/expert/topic/236/236802.shtm
昵称被占用了 2001-10-22
  • 打赏
  • 举报
回复
Sql Server Create Index 帮助:

Creates an index on a given table. The CREATE INDEX statement either changes the physical ordering of the table or provides the optimizer with a logical ordering of the table to increase efficiency for queries. When you create an index for the primary key, use the table- and column-level Primary Key constraint provided with the CREATE TABLE or ALTER TABLE statements.

For additional syntax information for the CREATE INDEX statement, see the Microsoft SQL Server Transact-SQL Reference.

Syntax

CREATE [UNIQUE] [CLUSTERED | NONCLUSTERED] INDEX index_name
ON [[database.]owner.]table_name (column_name [, column_name]...)
[WITH
[PAD_INDEX, ]
[[,] FILLFACTOR = fillfactor]
[[,] IGNORE_DUP_KEY]
[[,] SORTED_DATA | SORTED_DATA_REORG]
[[,] IGNORE_DUP_ROW | ALLOW_DUP_ROW]]
[ON segment_name]

where

PAD_INDEX

Specifies that the FILLFACTOR setting should be applied to the index node pages as well as to the data pages in the index.

Note The number of items on an index page is never less than two, regardless of how low the value of FILLFACTOR.

Remarks

Indexes are made up of pages that form a branching structure known as a B-tree. The starting page records ranges of values within the table. Each range on the starting page branches to another page that contains a more detailed range of values in the table. In turn, these index pages branch out to more layers, which increase the number of pages in the layer and narrow the range of data on each page.
The branching index pages are called node pages. The final layer in the branching structure is called the leaf layer. In a unique, non-clustered index, the ranges on each leaf layer page point to a specific row of data in the table. In a clustered index, the leaf layer is the data pages because the data is stored in the physical order specified in the index.

Setting FILLFACTOR to 100 in SQL Server version 6.5 has the same behavior as it does in SQL Server 6.0. Index node pages are filled completely and have no space for additional items.

Example

This example creates an index on the author's identification number in the authors table. Without the PAD_INDEX option, SQL Server version 6.5 creates leaf pages that are 10 percent full, but the node pages are filled almost completely. With PAD_INDEX the node pages are also 10 percent full.

Note At least two entries appear on the index pages of unique clustered indexes when PAD_INDEX is not specified.

CREATE INDEX au_id_ind
ON authors (au_id)
WITH PAD_INDEX, FILLFACTOR=10
Only_I 2001-10-22
  • 打赏
  • 举报
回复
余下的问题!

外键怎么解释?起什么作用?
再给几个建索引的例子。

希望各位大虾可以尽快帮我解决掉它!
我想结了这个贴子,再开一个,我又有新的问题了!
Only_I 2001-10-22
  • 打赏
  • 举报
回复
bluepower2008(蓝色力量)大虾,多谢教诲!由于我用到的是另一数据库的数据,就是虽另一个库的添加而添加,原有的库我无权改动!该如何是好?
Only_I 2001-10-22
  • 打赏
  • 举报
回复
我用的是sqlsever,

liujianjun_(流星尔)老兄的确高明,居然这都知道。

KingSunSha(弱水三千)大虾,我虽第一次在这里问问题,不过对大虾一早有耳闻,果然高手,可以劳烦您给解释其他几个问题吗?

ray2_ls(轻衫踏雪)兄,多谢!

Haiwer(Haiwer)兄,我有两本书,但对我提的问题并无解答,让我憔悴万分!建索引,我的书里没例子,大虾可否给贴几个,让我揣摩,

笨笨的说





bluepower2008 2001-10-22
  • 打赏
  • 举报
回复
1.对某字段建索引就是对表中该字段排序,并将排序结果保存在磁盘上,以后当以该字段检索时,直接通过排好序的该字段索引,用二分法查找,速度要加快很多; 创建的索引一般有两列,一列是已排序的字段,另一列是主关键字,方便定位查找,放在数据库中的数据页上,由数据库管理程序统一管理,你可以把它看成是一张特殊表; 主键在创建时,就默认地成为唯一索引,但外键我用得不多,不太清楚是否也自动建立索引.在一张表中,主键只能有一个,但索引可以有多个.如果你在频繁查询某一字段,速度很慢,就考虑给该字段建索引.
2.聚集是针对索引说的,如果表中某字段是聚集索引,那么表中记录在磁盘上的物理存储顺序就是按该字段的顺序来存放,如果你写select语句,不加order by条件,那么记录显示顺序就是按你的建立了聚集索引的那个字段的顺序.同样,一个表只允许有一个聚集索引.
3.对于你说的第3个问题,一般的解决方法是将数据分为工作数据和统计数据.工作数据在一段时间经常使用,大多为插入和修改;统计数据主要用于查询.你可以设置3个表,一个工作表,一个历史表,一个统计表.工作表中放一天,一周或一个月的记录,识情况而定,定期将过期数据移到历史表,同时将经常要查的统计信息按天或按小时统计后放到统计表中,加快查询统计的速度,要查询明细时再查询历史表.以上设计应该可以满足你的要求.定时移数和统计功能,可以写成存储过程,用数据库的定时任务来执行.
昵称被占用了 2001-10-22
  • 打赏
  • 举报
回复
概念的问题应该看书,书里比这里说的清楚.
象你所说的情况,要查询快,应该建立"输入时间"字段的索引,在查询条件用
输入时间>.... and 输入时间<....
这样大数据量也不是问题.
ray2_ls 2001-10-22
  • 打赏
  • 举报
回复
我不懂,帮你up~~~~~
KingSunSha 2001-10-22
  • 打赏
  • 举报
回复
索引其实也是有物理存储的,比如对表A中的两列(col1,col2)建立索引,数据库会专门开一块存储区域,按照col1,col2排序存入该存储区域。当对这两个列进行条件查询的时候,数据先到这块区域中搜索,因为已经经过排序,所以搜索的速度比直接对表查询快的多。但是也带来了副作用,即每次对插入新纪录或者更新表中的这两个列时,数据库要对索引区重新排序。
这就是平常所说的“索引是把双刃剑”的原因。
流星尔 2001-10-22
  • 打赏
  • 举报
回复
你用的是sqlsever数据库吧。
索引相当于排序,是为了提高查询数据的处理而设置。能告诉你是用什么数据库的吗。
要想查询操作快一点,你可以设置条件,这样,就只会对符合条件的数据进行处理操作。数据自然能保证

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧