添加唯一索引
alter table TG_FRIENDSHIPS add index index_friendships_followerId(followerId);
添加普通所以
alter table TG_FRIENDSHIPS add unique index(friendId,followerId);
添加mysql主键
alter table Books add primary key(id);
设置自增
alter table Books auto_increment=1;
alter table `TG_PERMISSION` change `id` `id` bigint not null auto_increment;
修改类型
alter table topics change hotico hot_count int(4)
alter table address modify column city varchar(50)
修改默认值
alter table topics alter hot_count set default 1;
alter table TG_USER_COUNSELOREXTINFO MODIFY `edit_time`  timestamp on update current_timestamp;
alter table TG_USER_COUNSELOREXTINFO MODIFY `create_time`  timestamp not null default current_timestamp;
alter table TG_USER_COUNSELOREXTINFO MODIFY `edit_time`  timestamp not null default current_timestamp on update current_timestamp;
修改数据库的编码
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
使用描述:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ] 
or ADD INDEX [index_name] (index_col_name,...) 
or ADD PRIMARY KEY (index_col_name,...) 
or ADD UNIQUE [index_name] (index_col_name,...) 
or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} 
or CHANGE [COLUMN] old_col_name create_definition 
or MODIFY [COLUMN] create_definition 
or DROP [COLUMN] col_name 
or DROP PRIMARY KEY 
or DROP INDEX index_name 
or RENAME [AS] new_tbl_name 
or table_options


评论