【Mysql】细节补充,约束、索引等

约束:

显示建表语句:show create table 表名

查询表中的约束:SELECT * FROM information_schema.`TABLE_CONSTRAINTS`  where table_name = '表名'

添加约束:alter table 表名 add unique key 约束名 (列1[,列2……])

删除约束:#alter table 表名 drop key 约束名;

索引:
显示表已添加的索引:show index from customer

添加:

1.添加PRIMARY KEY(主键索引) 
ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 
2.添加UNIQUE(唯一索引) 
ALTER TABLE `table_name` ADD UNIQUE ( `column` ) 
3.添加INDEX(普通索引) 
ALTER TABLE `table_name` ADD INDEX index_name ( `column` ) 
4.添加FULLTEXT(全文索引) 
ALTER TABLE `table_name` ADD FULLTEXT ( `column`) 
5.添加多列索引 
ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )

删除:

drop index index_name on table_name ;

alter table table_name drop index index_name ;

alter table table_name drop primary key ;

猜你喜欢

转载自blog.csdn.net/the_fool_/article/details/82996859