雅虎新闻|| BBC新闻|| CNN新闻|| 美元指数|| 中国期货指数|| 股票指数|| 黄金|| 外汇|| 英汉互译|| 昭放工具
163邮箱|| 126邮箱|| 新浪邮箱|| 企业邮箱|| 21cn邮箱|| tom邮箱|| 搜狐邮箱|| hotmail邮箱|| msn邮箱|| qq邮箱

用户登录

设为主页| 淘宝铺| 加入收藏|
您的IP:18.220.66.151您的操作系统:Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
个人便签
知识库
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';

星期一, 08/11/2014 - 10:28 — 杨超