天天看點

MySQL添加字段和修改字段的方法

1.登入資料庫

>mysql -u root -p 資料庫名稱

2.查詢所有資料表

>show tables;

3.查詢表的字段資訊

>desc 表名稱;

4.1添加表字段

alter table table1 add transactor varchar(10) not Null;

alter table   table1 add id int unsigned not Null auto_increment primary key

4.2.修改某個表的字段類型及指定為空或非空

>alter table 表名稱 change 字段名稱 字段名稱 字段類型 [是否允許非空];

>alter table 表名稱 modify 字段名稱 字段類型 [是否允許非空];

4.3.修改某個表的字段名稱及指定為空或非空

>alter table 表名稱 change 字段原名稱 字段新名稱 字段類型 [是否允許非空

4.4如果要删除某一字段,可用指令:ALTER TABLE mytable DROP 字段 名;