總會有這樣的時刻,突然要在表中加個字段,加個索引,或者加個字段,或者是修改給字段, 一時間想不起來用哪個命令,現(xiàn)在就將平時用到的一部分命令寫出來,方便使用: 1.增加表中的字段 alter table tablename add new_field type not null default '0'; exa
總會有這樣的時刻,突然要在表中加個字段,加個索引,或者加個字段,或者是修改給字段,
一時間想不起來用哪個命令,現(xiàn)在就將平時用到的一部分命令寫出來,方便使用:
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設(shè)置字段默認(rèn)值
alter table fashion_warning_work alter column is_del set default 0;
先寫這些吧,后邊在慢慢補上!
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com