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

1、登錄數據庫 

   >mysql -u root -p 數據庫名稱 

 2、查詢所有數據表 

   >show tables; 

 3、查詢表的字段信息 

   >desc 表名稱; 

 4.1修改表名 

   alter table table1 rename table2; 

 4.2添加表字段 

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

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

 4.3修改某個表的字段類型及指定爲空或非空 

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

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

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

 4.4修改某個表的字段名稱及指定爲空或非空 

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

 4.5如果要刪除某一字段,可用命令:

   ALTER TABLE mytable DROP 字段名

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