mysql添加字段的方法并不複雜,下面将為您詳細介紹mysql添加字段和修改字段等操作的實作方法,希望對您學習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 字段 名;