mysql设置非空有关问题

mysql设置非空问题

+——–+———-+———-+——-+——-+

| userid | password | username | email | phone |

+——–+———-+———-+——-+——-+

| 110 | 123456 | 111110 | NULL | NULL |

+——–+———-+———-+——-+——-+

在创建时没设置为空

  表创建完成后

  当表中没记录 我要设置 让password为非空 SQL语句怎么写




Alter table `你的表名` modify `password` varchar(20) NOT NULL;



SQL code

mysql> create table t_zhyou110z (
    ->  userid int primary key,
    ->  password varchar(10)
    -> );
Query OK, 0 rows affected (0.13 sec)

mysql> desc t_zhyou110z;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| userid   | int(11)     | NO   | PRI | NULL    |       |
| password | varchar(10) | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.11 sec)

-- 修改password 为not null / ACMAIN
mysql> alter table t_zhyou110z modify password varchar(10) not null;
Query OK, 0 rows affected (0.22 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc t_zhyou110z;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| userid   | int(11)     | NO   | PRI | NULL    |       |
| password | varchar(10) | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql>


探讨
3Q 还是你们呢 这样写还可以长度 要修改类型怎么写呢
mysql设置非空有关问题

相关文章:

你感兴趣的文章:

标签云: