SQL索引
--索引 index create [ unique ] [ clustered |nonclustered ] index index_name on <object> ( column_name [ asc | desc ] [ ,...n ] ) [ include ( column_name [ ,...n ] ) ] [ where <filter_predicate> ] [ with <backward_compatible_index_option> [ ,...n ] ] [ on { partition_scheme_name ( column_name ) | filegroup_name | "default" } ] [ FILESTREAM_ON { filestream_filegroup_name | partition_scheme_name | "NULL" } ] [ ; ] <object> ::= { [ database_name. [ owner_name ] . | owner_name. ] table_or_view_name } <backward_compatible_index_option> ::= { PAD_INDEX ={ON |OFF} --指定是否索引填充。默认为 OFF。 | FILLFACTOR = fillfactor --用于指定在创建索引时,每个索引页的数据占索引页大小的百分比,fillfactor 的值为1到100。 | SORT_IN_TEMPDB={ON |OFF} --用于指定创建索引时的中间排序结果将存储在 tempdb 数据库中。 默认为 OFF。 | IGNORE_DUP_KEY ={ON |OFF} --指定在插入操作尝试向唯一索引插入重复键值时的错误响应。默认为 OFF。 | STATISTICS_NORECOMPUTE={ON |OFF --用于指定过期的索引统计是否自动重新计算。 默认为 OFF。 | DROP_EXISTING ={ON |OFF} --表示如果这个索引还在表上就 drop 掉然后在 create 一个新的。 默认为 OFF。 | ONLINE = {ON |OFF} --表示建立索引时是否允许正常访问,即是否对表进行锁定。默认为 OFF。 } --创建简单允许重复索引 create index ix_Persons on Persons(id asc,name desc) --创建唯一索引 create unique index ix_Persons on Persons(id asc,name desc) --创建聚集索引 create clustered index ix_Persons on Persons(id asc,name desc) --创建非聚集索引 create nonclustered index ix_Persons on Persons(id asc,name desc) --创建唯一聚集索引 create unique clustered index ix_Persons on Persons(id asc,name desc) --创建唯一非聚集索引 create unique nonclustered index ix_Persons on Persons(id asc,name desc) --修改索引 alter index { index_name | ALL } on <object> { rebuild [ [PARTITION = ALL] [ WITH ( <rebuild_index_option> [ ,...n ] ) ] | [ PARTITION = partition_number [ WITH ( <single_partition_rebuild_index_option> [ ,...n ] ) ] ] ] | disable | REORGANIZE [ PARTITION = partition_number ] [ WITH ( LOB_COMPACTION = { ON | OFF } ) ] | SET ( <set_index_option> [ ,...n ] ) } [ ; ] --禁用名为 NonClu_Index 的索引 alter index NonClu_Index on Student disable --删除指定表 Student 中名为 Index_StuNo_SName 的索引 drop index Student.Index_StuNo_SName --检查表 Student 中索引 UQ_S_StuNo 的碎片信息 dbcc showcontig(Student,UQ_S_StuNo) --整理 Test 数据库中表 Student 的索引 UQ_S_StuNo 的碎片 dbcc indexdefrag(Test,Student,UQ_S_StuNo) --更新表 Student 中的全部索引的统计信息 update statistics Student
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现