[Desafío avanzado de MYSQL] Niuke.com: Operaciones de tablas e índices

Crea la tabla:

 

CREATE TABLE
[IF NOT EXISTS] tb_name -- 不存在才创建,存在就跳过
(column_name1 data_type1 -- 列名和类型必选
  [ PRIMARY KEY -- 可选的约束,主键
   | FOREIGN KEY -- 外键,引用其他表的键值
   | AUTO_INCREMENT -- 自增ID
   | COMMENT comment -- 列注释(评论)
   | DEFAULT default_value -- 默认值
   | UNIQUE -- 唯一性约束,不允许两条记录该列值相同
   | NOT NULL -- 该列非空
  ], ...
) [CHARACTER SET charset] -- 字符集编码
[COLLATE collate_value] -- 列排序和比较时的规则(是否区分大小写等)

Código:

create table if not exists user_info_vip(
 id int primary key auto_increment comment'自增ID',
 uid int unique not null comment '用户ID',
 nick_name varchar(64) comment'昵称',
achievement int default 0 comment'成就值',
`level` int comment '用户等级',
job varchar(32)comment '职业方向',
register_time datetime default current_timestamp comment'注册时间'
)character set utf8 collate utf8_general_ci;

Modificar la tabla:

    { ADD COLUMN <列名> <类型>  -- 增加列
     | CHANGE COLUMN <旧列名> <新列名> <新列类型> -- 修改列名或类型
     | ALTER COLUMN <列名> { SET DEFAULT <默认值> | DROP DEFAULT } -- 修改/删除 列的默认值
     | MODIFY COLUMN <列名> <类型> -- 修改列类型
     | DROP COLUMN <列名> -- 删除列
     | RENAME TO <新表名> -- 修改表名
     | CHARACTER SET <字符集名> -- 修改字符集
     | COLLATE <校对规则名> } -- 修改校对规则(比较和排序时用到)

 

 

alter table user_info add school varchar(15) after level;
alter table user_info change job profession varchar(10);
alter table user_info modify achievement int(11) default 0;

Mesa plegable:

 

drop table if exists
 exam_record_2011,exam_record_2012,exam_record_2013,exam_record_2014;

Crear un índice:

CREATE 
  [UNIQUE -- 唯一索引
  | FULLTEXT -- 全文索引
  ] INDEX index_name ON table_name -- 不指定唯一或全文时默认普通索引
  (column1[(length) [DESC|ASC]] [,column2,...]) -- 可以对多列建立组合索引  

 

 

create index idx_duration on examination_info(duration);
create unique index uniq_idx_exam_id on examination_info(exam_id);
create fulltext index full_idx_tag on examination_info(tag);

 

Índice de caída:

drop index uniq_idx_exam_id on examination_info;
drop index full_idx_tag on examination_info;

Supongo que te gusta

Origin blog.csdn.net/m0_52043808/article/details/124184981
Recomendado
Clasificación