《sqlserver2016数据库应用与开发黄能耿)配套资源2.17-索引》由会员分享,可在线阅读,更多相关《sqlserver2016数据库应用与开发黄能耿)配套资源2.17-索引(18页珍藏版)》请在金锄头文库上搜索。
1、第2章 数据定义 2.6 数据定义SQL语言方式 2.6.4 索引操作,2.6 数据定义SQL语言方式,2.6.1 体验SQL 2.6.2 数据库操作 2.6.3 数据表操作 1 创建表 2 数据完整性约束 3 变更表 4 丢弃(删除)表 2.6.4 索引操作,2.6.4 索引操作,2.6.1 体验SQL 2.6.2 数据库操作 2.6.3 数据表操作 2.6.4 索引操作 1 索引的概念 2 创建索引 3 索引的使用 4 查看索引 5 丢弃(删除)索引,1 索引的概念,索引就像“汉语词典”中的检字表,可以加快查找的速度,而不必从头到尾进行查找,索引也有这二个作用:1、提高查找速度;2、发现相
2、同的值,索引的种类,索引的特点,索引的应用,2.6.4 索引操作,2.6.1 体验SQL 2.6.2 数据库操作 2.6.3 数据表操作 2.6.4 索引操作 1 索引的概念 2 创建索引 3 索引的使用 4 查看索引 5 丢弃(删除)索引,2 创建索引,- 例子:为学生表的姓名列建立索引 Create index idx_student on tbl_student (col_name);,- 语法格式 Create unique index on ;,创建索引,- 例子:为学生表的姓名列建立索引 Create index idx_student on tbl_student (col_na
3、me);,2.6.4 索引操作,2.6.1 体验SQL 2.6.2 数据库操作 2.6.3 数据表操作 2.6.4 索引操作 1 索引的概念 2 创建索引 3 索引的使用 4 查看索引 5 丢弃(删除)索引,3 索引的使用,2.6.4 索引操作,2.6.1 体验SQL 2.6.2 数据库操作 2.6.3 数据表操作 2.6.4 索引操作 1 索引的概念 2 创建索引 3 索引的使用 4 查看索引 5 丢弃(删除)索引,4 查看索引,- 例子:查看tbl_student表的索引信息 Exec sp_helpindex tbl_student,- 语法格式 Exec sp_helpindex ;,
4、- 创建学生表 Create table tbl_student ( id_tbl_student int not null primary key identity, - 主键 col_student_no varchar(12) not null unique, - 学号,唯一性约束 col_name varchar(50) not null, col_sex char(1) null, col_status tinyint null, col_birthday date null, col_id_no varchar(18) null unique, - 学号,身份证号 col_mobi
5、le varchar(16) null unique, - 学号,手机号码 id_tbl_class int not null references tbl_class (id_tbl_class) ); - 例子:为学生表的姓名列建立索引 Create index idx_student on tbl_student (col_name); - 普通索引,2.6.4 索引操作,2.6.1 体验SQL 2.6.2 数据库操作 2.6.3 数据表操作 2.6.4 索引操作 1 索引的概念 2 创建索引 3 索引的使用 4 查看索引 5 丢弃(删除)索引,5 丢弃(删除)索引,- 例子:删除为学生表的姓名列建立的索引 DROP INDEX tbl_student.idx_student;,- 语法格式 Drop index ;,2.6 数据定义SQL语言方式,2.6.1 体验SQL 2.6.2 数据库操作 2.6.3 数据表操作 2.6.4 索引操作 1 索引的概念 2 创建索引 3 索引的使用 4 查看索引 5 丢弃(删除)索引,