一、表的创建、修改与删除
1、创建一张新表
【设置日期默认值、设置id自增】
【注意有备注添加备注COMMENT】
CREATE TABLE user_info_vip(
id int(11) primary key auto_increment comment "自增ID", -- 主键默认不允许为空
uid int(11) unique key not null comment "用户ID",
nick_name varchar(64) comment "昵称",
achievement int(11) default 0 comment "成就值",
level int(11) comment "用户等级",
job varchar(32) comment "职业方向",
register_time datetime default current_timestamp comment "注册时间" -- current_timestamp表示当前
)DEFAULT CHARSET=UTF8
2、修改表
ALTER TABLE user_info ADD COLUMN school VARCHAR(15) AFTER level;
ALTER TABLE user_info RENAME COLUMN job TO profession;
ALTER TABLE user_info MODIFY COLUMN profession VARCHAR(10) COMMENT "";
ALTER TABLE user_info MODIFY COLUMN achievement INT(11) DEFAULT 0 COMMENT "";
3、删除存在的表
DROP TABLE IF EXISTS exam_record_2011;
DROP TABLE IF EXISTS exam_record_2012;
DROP TABLE IF EXISTS exam_record_2013;
DROP TABLE IF EXISTS exam_record_2014;
二、索引的创建、删除
1、创建普通索引、唯一性索引、全文索引
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);
-- ON 表(列)
2、删除索引
DROP INDEX uniq_idx_exam_id ON examination_info;
DROP INDEX full_idx_tag ON examination_info;
本文来自博客园,作者:哥们要飞,转载请注明原文链接:javascript:void(0)p/16208430.html