mysql 字段操作

1、添加字段

ALTER TABLE lucky_user ADD COLUMN id_type TINYINT NOT NULL DEFAULT '0' COMMENT "0: 普通用户,1:网络红人,2:明星" AFTER type_id ;

2、删除字段

alter table lucky_user drop column id_type

3、改变字段

alter table lucky_event_award change description title char(40) not null default "";

3.1 修改字段的默认值

alter table ${table_prefix}${i} alter column user_name drop default; // 删除

alter table ${table_prefix}${i} alter column user_name set default '你好'; // 添加

4、修改表面

alter table table_name rename table_name_new;

5、表中的创建时间和更新时间

alter table xxx add column created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;

alter table xxx add column updated_at timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP;

posted @ 2016-06-25 11:39  Thomas_188  阅读(161)  评论(0编辑  收藏  举报