您好,欢迎访问一九零五行业门户网

我们如何将 NOT NULL 约束应用于现有 MySQL 表的列?

我们可以借助 alter table 语句将 not null 约束应用于现有 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: 0mysql> describe test123;+-------+---------+------+-----+---------+-------+| field | type | null | key | default | extra |+-------+---------+------+-----+---------+-------+| id | int(11) | no | | null | || date | date | yes | | null | |+-------+---------+------+-----+---------+-------+2 rows in set (0.06 sec)
以上就是我们如何将 not null 约束应用于现有 mysql 表的列?的详细内容。
其它类似信息

推荐信息