next up previous contents
Next: CHANGE 改變 Up: ALTER 語法 Previous: ADD 新增   Contents   DYWANG_HOME

MODIFY 修改

  1. MODIFY 改變資料表 tbl 欄位 c 的格式由原固定 1 個字元改為 10 個字元。
    mariadb root@localhost:dyw> alter table tbl modify c char(10);                  
    You're about to run a destructive command.
    Do you want to proceed? (y/n): y
    Your call!
    Query OK, 4 rows affected
    Time: 0.152s
    
  2. 再查看資料表 tbl 的欄位格式。
    mariadb root@localhost:dyw> show columns from tbl;                              
    +-----------------+--------------+------+-----+---------+----------------+
    | Field           | Type         | Null | Key | Default | Extra          |
    +-----------------+--------------+------+-----+---------+----------------+
    | ti              | tinyint(4)   | YES  |     | <null>  |                |
    | id              | int(11)      | NO   | PRI | <null>  | auto_increment |
    | c               | char(10)     | YES  |     | <null>  |                |
    | title           | varchar(100) | NO   |     | <null>  |                |
    | author          | varchar(40)  | NO   |     | <null>  |                |
    | submission_date | date         | YES  |     | <null>  |                |
    +-----------------+--------------+------+-----+---------+----------------+
    
    6 rows in set
    Time: 0.024s
    



De-Yu Wang 2020-04-07