标签:sub 主键索引 一个 文件 数据 div date pre 主键
1、索引
# 给 name 字段创建索引 aa mysql> create index aa on t_student(name); # 查看索引 mysql> show index from t_student; +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-----------+------------+----------+--------------+-------------+-----------+--- | t_student | 1 | aa | 1 | name | A | 2 | NULL | NULL | YES | BTREE | | +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
# 删除索引 aa mysql> drop index aa on t_student;
# 给 name 字段创建唯一索引 mysql> create unique index bb on t_student(name); mysql> show index from t_student; +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | t_student | 0 | bb | 1 | name | A | 2 | NULL | NULL | YES | BTREE | | +-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
# 给 score 字段添加主键索引 mysql> alter table t_course add primary key(score); mysql> show index from t_course; +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | t_course | 0 | PRIMARY | 1 | score | A | 6 | NULL | NULL | | BTREE | | +----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2、视图
# 创建视图 v_stu mysql> create view v_stu as (select id,name,age from t_student);
# 查看创建的视图 v_stu mysql> show tables; +-------------------+ | Tables_in_student | +-------------------+ | t_course | | t_student | | v_stu | +-------------------+ mysql> select * from v_stu; +----+----------+------+ | id | name | age | +----+----------+------+ | 1 | zhangsan | 18 | | 2 | wangwu | 20 | | 3 | zhaoliu | 19 | | 4 | lisi | 22 | +----+----------+------+
mysql> alter view v_stu as (select id,name from t_student); mysql> select * from v_stu; +----+----------+ | id | name | +----+----------+ | 4 | lisi | | 2 | wangwu | | 1 | zhangsan | | 3 | zhaoliu | +----+----------+
# 删除视图 v_cou mysql> drop view v_cou; mysql> show tables; +-------------------+ | Tables_in_student | +-------------------+ | t_course | | t_student | | v_stu | +-------------------+
标签:sub 主键索引 一个 文件 数据 div date pre 主键
原文地址:https://www.cnblogs.com/ZhengYing0813/p/12675579.html