mysql创建索引

修改原有字段名称及类型:
ALTER TABLE bulletin CHANGE uid username VARCHAR(50) NOT NULL DEFAULT '';

添加新字段:

alter table bulletin add citycode varchar(6) not null default 0; # 城市代码

1.创建数据库时设置编码

create database test character set utf8;

2.创建表时设置编码

create table test(id int primary key)DEFAULT charset=utf8;

3.修改数据库编码

alter database test character set utf8;

4.修改表默认编码

alter table test character set utf8;

5.修改字段编码

alter table test modify col_name varchar(50) CHARACTER SET utf8;

---------添加索引方法---------

1.添加PRIMARY KEY(主键索引)

mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )

2.添加UNIQUE(唯一索引)

mysql>ALTER TABLE `table_name` ADD UNIQUE (

`column`

)

2.添加UNIQUE(唯一索引)

mysql>ALTER TABLE `table_name` ADD UNIQUE (

`column`

)

3.添加INDEX(普通索引)
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column` )


4.添加FULLTEXT(全文索引)
mysql>ALTER TABLE `table_name` ADD FULLTEXT (

`column`

)

5.添加多列索引
mysql>ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )

 

posted @ 2021-02-22 12:23  星空之主  阅读(228)  评论(0编辑  收藏  举报