mysql表結構的處理

use test;
create table teachers(
  id int primary key,
  name varchar(20)
);
修改表結構--添加字段:
alter table teachers
add column age int not null default 0 after name;(在姓名字段後添加)

修改表結構--刪除字段:
alter table teachers drop column age;

添加主鍵
alter table teachers add primary key (id);
刪除主鍵
alter table teachers drop primary key;

重命名列
alter table teachers change age sex int;

改變列的類型
alter table teachers change sex sex varchar(2) not null;

重命名錶
alter table teachers rename boss;

//給主鍵添加自動增長
alter table boss change id id int(20) auto_increment;
//不能直接刪除主鍵,先刪自動增長,再刪主鍵
alter table boss change id id int(10);
alter table boss drop primary key;

查看字符集
/s;
//以下未經過測試
//修改數據庫的字符集
//修改表的字符集
alter database test default character set utf8;
alter table teachers default character set utf8;
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章