Mysql 新增字段 修改字段 刪除字段

2022-07-16 12:18:13 字數 343 閱讀 8715

alter table 表名 add column 欄位名 字段型別(字段長度) default 預設值 comment '注釋'

例如:alter table order add column  code char(6) default null comment '優惠碼'

2、修改字段(修改欄位名、字段型別、長度)

a、修改欄位名:

alter table 表名 change 舊欄位名  新欄位名

b、修改字段型別

alter table 表名 modify 欄位名 字段型別(字段長度)

3、刪除字段

alter table 表名 drop 欄位名 

Mysql 新增字段 修改字段 刪除字段

alter table 表名 add 欄位名 字段型別 字段長度 default 預設值 comment 注釋 例如 alter table order add code char 6 default null comment 優惠碼 2 修改字段 修改欄位名 字段型別 長度 a 修改欄位名 alt...

MySQL新增字段,修改字段,刪除字段,修改表資訊

mysql的簡單語法,常用,卻不容易記住。當然,這些sql語法在各資料庫中基本通用。下面列出 一 查詢資訊 1.登入資料庫 mysql u root p 資料庫名稱 2.查詢所有資料表 show tables 3.查詢表的字段資訊 desc 表名稱 二 修改表資訊 1.修改表名 2.修改表注釋 三 ...

mysql欄位新增 型別修改 字段刪除sql語句

本文介紹產品上線資料庫更新常用sql語句,包括新增修改字段設定型別 長度 預設值 備註等操作,後續會持續更新alter table test add column create by varchar 10 not null default system comment 建立者 after id al...