>  기사  >  데이터 베이스  >  Mysql 表操作的基本语法

Mysql 表操作的基本语法

WBOY
WBOY원래의
2016-06-07 15:33:371100검색

总会有这样的时刻,突然要在表中加个字段,加个索引,或者加个字段,或者是修改给字段, 一时间想不起来用哪个命令,现在就将平时用到的一部分命令写出来,方便使用: 1.增加表中的字段 alter table tablename add new_field type not null default '0'; exa

   总会有这样的时刻,突然要在表中加个字段,加个索引,或者加个字段,或者是修改给字段,

   一时间想不起来用哪个命令,现在就将平时用到的一部分命令写出来,方便使用:


1.增加表中的字段
 alter table tablename add new_field  type not null default '0';
 example:
 alter table people_final_base add is_del  int(11)  not null default 0;

2.修改表中字段名字
alter table  tablename  change  old_item  new_item  old_type;
example:
alter table  people_final_base  change  name chinese_name  varchar(50);

3.修改字段类型
alter table   tablename change  filed_name   filed_name   new_type;   
example:
alter table  people_final_base  change  create_date create_date  varchar(100);

4.删除字段
alter table tablename drop column column_name;
example:
alter table people_final_base drop  column temp0;

5.添加主键
alter table tablename add primary key(item);
alter table fashion_relation_partner add primary key(pps_key);

6.修改主键
思路:先删除主键,然后再添加主键
alter table tablename drop primary key;
alter table tablename add primary key(item);
example:
alter table fashion_relation_partner drop primary key;
alter table fashion_relation_partner add primary key(pps_key);

7设置字段默认值
alter table fashion_warning_work alter column is_del set default 0;



先写这些吧,后边在慢慢补上!


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.