设为首页 加入收藏

TOP

mysql 修改表/字段 增加/删除表索引
2011-06-12 21:41:47 来源: 作者: 【 】 浏览:78次 评论:0

mysql教程 修改表/字段 增加/删除表索引

create table test (blob_col blob, index(blob_col(10)));在mysql 5.1中,对于myisam和innodb表,前缀可以达到1000字节长。请注意前缀的限制应以字节为单位进行测量,而create table语句中的前缀长度解释为字符数。当为使用多字节字符集的列指定前缀长度时一定要加以考虑。

还可以创建fulltext索引。该索引可以用于全文搜索。只有myisam存储引擎支持fulltext索引,并且只为char、varchar和text列。索引总是对整个列进行,不支持局部(前缀)索引

 

加索引
mysql> alter table 表名 add index 索引名 (字段名1[,字段名2 …]);

例子: mysql> alter table employee add index emp_name (name);
加主关键字的索引
mysql> alter table 表名 add primary key (字段名);
例子: mysql> alter table employee add primary key(id);
加唯一限制条件的索引
mysql> alter table 表名 add unique 索引名 (字段名);
例子: mysql> alter table employee add unique emp_name2(cardnumber);
mysql alter语法运用:查看某个表的索引
mysql> show index from 表名;

例子: mysql> show index from employee;

删除某个索引
mysql> alter table 表名 drop index 索引名;

例子: mysql>alter table employee drop index emp_name;

修改表:增加字段:mysql> alter table table_name add field_name field_type;
查看表:mysql> select * from table_name;

修改原字段名称及类型:mysql> alter table table_name change old_field_name new_field_name field_type;

删除字段:mysql alter table table_name drop field_name;


最后补充一点

多列索引
mysql可以为多个列创建索引。一个索引可以包括15个列。对于某些列类型,可以索引列的前缀(参见7.4.3节,“列索引”)。

多列索引可以视为包含通过连接索引列的值而创建的值的排序的数组。

mysql按这样的方式使用多列索引:当你在where子句中为索引的第1个列指定已知的数量时,查询很快,即使你没有指定其它列的值。

假定表具有下面的结构:

create table test (    id int not null,    last_name char(30) not null,    first_name char(30) not null,    primary key (id),    index name (last_name,first_name));name索引是一个对last_name和first_name的索引。索引可以用于为last_name,或者为last_name和first_name在已知范围内指定值的查询。因此,name索引用于下面的查询:

select * from test where last_name='widenius'; select * from test    where last_name='widenius' and first_name='michael'; select * from test    where last_name='widenius'    and (first_name='michael' or first_name='monty'); select * from test    where last_name='widenius'    and first_name >='m' and first_name < 'n';然而,name索引不用于下面的查询:

select * from test where first_name='michael'; select * from test    where last_name='widenius' or first_name='michael';

mysql 修改表/字段 增加/删除表索引 更多相关文章

您看到此篇文章时的感受是:
Tags: 责任编辑:administrator
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇mysql创建数据库几种方法 下一篇mysql alter 修改字名 表名 结构 ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章

广告位