mysql :mysql 表的常见操作

 

mysql单表操作:


取消列的自增长:
alter table cust_consume change cid cid int;

 

设置自增长列:
alter table cust_consume 
modify `cid` int(11) auto_increment;

 

设置自增列的起始值:
alter table cust_consume auto_increment=10;

 

为表添加备注:
alter table cust_consume comment '自动分配表'

 

 修改表的字符集
alter table temp04 CHARSET=utf8

 


-- 添加字段并将字段设置为主键 ,设置为第一列
alter table  tabelname  
add   conlumn_name  data_type default 0 not null auto_increment  First,
add   primary key (new_field_id);

例子:
alter table  temp01  
add   eid  int   not null auto_increment ,
add   primary key (eid);

 

-- 在某个字段后面添加一列

alter table  tabelname  
add   conlumn_name  data_type default 0 after column_name1,


-- 修改字段名
alter table tablename   
change   old_column_name    new_column_name  oldType;

例子:
alter table temp01   
change   gameAccount   Account  varchar(100);

这个oldType 不一定是老的数据类型,只要是一个兼容的数据类型就行,但是为了
保证数据的正确性(数据截断) ,最好给定老的数据类型


--修改字段类型 ,这个地方很奇怪 ,不知道为什么要写两遍列名
alter table  tablename    
change   filed_name  filed_name  new_type;

例子:
alter table   temp01    
change  gameAccount  gameAccount   char(100);

 

 

 

你可能感兴趣的:(mysql,change,modify,comment)