我們可以借助 ALTER TABLE 語句將 NOT NULL 約束應(yīng)用于現(xiàn)有 MySQL 表的列。
語法
ALTER TABLE table_name MODIFY colum_name datatype NOT NULL;
登錄后復制
示例
mysql> Create table test123(ID INT, Date DATE); Query OK, 0 rows affected (0.19 sec) mysql> Describe test123; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | ID | int(11) | YES | | NULL | | | Date | date | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.04 sec) mysql> ALTER TABLE test123 MODIFY ID INT NOT NULL; Query OK, 0 rows affected (0.54 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> Describe test123; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | ID | int(11) | NO | | NULL | | | Date | date | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.06 sec)
登錄后復制
以上就是我們?nèi)绾螌?NOT NULL 約束應(yīng)用于現(xiàn)有 MySQL 表的列?的詳細內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!