Heim  >  Artikel  >  Datenbank  >  Mysql 表操作的基本语法

Mysql 表操作的基本语法

WBOY
WBOYOriginal
2016-06-07 15:33:371099Durchsuche

总会有这样的时刻,突然要在表中加个字段,加个索引,或者加个字段,或者是修改给字段, 一时间想不起来用哪个命令,现在就将平时用到的一部分命令写出来,方便使用: 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;



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


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn