我们今天主要向大家介绍的是mysql alter语法的实际运用,如果你对这一技术,心存好奇的话,以下的文章将会揭开它的神秘面纱。
        以下的文章主要介绍的是mysql alter语法的实际运用,我们大家都知道mysql alter语法在实际应用中的比例还是很大的,所以了解一下mysql alter语法的实际运用可以很好的选择。 
mysql alter语法中alter [ignore] table tbl_name alter_spec [, alter_spec ...] 
 代码如下: 
alter_specification: 
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 
eg: 
mysql> alter table topics change hotico hot_count int(4); 
mysql> alter table topics alter hot_count set default 1;
补充: 
加索引 
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;
   
 
   