mysql数据库实验9

3.使用create index语句,根据xs表的姓名列建立一个降序BTREE索引xs_xh。

create index xs_xh
on xs(姓名 desc);

4. 使用alter table语句,根据xs表的姓名列建立一个降序BTREE索引xs_xh¬a。

alter table xs
add index xs_xha using btree (姓名 desc);

5. 使用create table语句,根据xs1表的姓名列建立一个降序BTREE索引xs_xh¬b。

create table xs1
(
    学号 	varchar(6) null,
    姓名 	varchar(8) not null primary key,
    出生日期 datetime null,
    index xs_xhb using btree(姓名 desc)
);

6. 使用三种方式,在xs_kc表的课程号和成绩列上建立一个复合索引xskc¬_kch_cj

create index xskc_kch_cj
    on xs_kc(课程号,成绩);

alter table xs_kc
add index xskc_kch_cj(课程号,成绩);

create table xs_kc1
(
学号 char(6) not null,
课程号 char(3) not null,
成绩 tinyint(1) null,
学分 tinyint(1) null,
primary key(学号,课程号) ,
Index xskc_kch_cj(课程号,成绩)
);

7. 在xs_kc表的课程号列上创建一个非唯一的索引xskc_kch

alter table xs_kc
add index xskc_kch using btree(课程号);

8. 在xs表(假设表中主键未定)的姓名和性别列建立复合索引xs_xm_xb,并查看表中创建的索引的情况。

create index xs_xm_xb
on xs (姓名,性别);

9. 创建test数据库,在test数据库创建xs表,带有姓名和出生日期的联合主键,并在学号列上创建索引。

use text;
create table xs
(
学号 char(6) not null ,
姓名 char(8) not null,
专业名 char(10) null,
性别 tinyint(1) not null default 1,
出生日期 date not null,
总学分 tinyint(1) null,
照片 blob null,
备注 text  null,
Primary key(姓名,出生日期),
Index search(学号)
) engine = innodb;

10. 使用Drop index语句删除xs表上的xs_xm_xb索引。

drop index xs_xm_xb on xs;

11. 使用alter table语句删除xs表上的xs_xh索引。

alter table xs
drop index xs_xh;

12. 对YGGL数据库的Employees表中的WorkYear列建立索引。

create index wy
On employees(WorkYear);

13. 在Employees表的Name和Sex列建立复合索引。

create index namesex
 on employees(name,sex);

14. 对Departments表的DepartmentName列建立唯一性索引,并查看表中索引

create unique index dtn
on Departments(DepartmentName);

15. 对Employees表的PhoneNumber列前6位进行前缀索引。

create unique index pn
on employees (phonenumber(6)asc);

16. 向Employees表中的出生日期列添加一个唯一性索引,在姓名列和电话列上添加一个复合索引。

create unique index bd
on employees(birthday);

17. 假设Departments表中没有主键,使用alter table 语句将DepartmentID列设为主键。

alter table departments add Primary key(DepartmentID);

18. 创建与Departments表相同结构设为表Departments1,将DepartmentName设为主键,在DepartmentID上建立一个索引。

create table departments1
(
departmentID char(3) not null ,
departmentName char(20) not null,
note text null,
Primary key(departmentName),
Index id(departmentID)
);

19. 使用drop index语句删除Employees表上的索引。

drop index pn on employees;
drop index xh_xs on xs;

20. 使用alter table语句删除Departments表上的主键和索引。

alter table departments
drop primary key;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值