+--------+----------+----------+-------+-------+
| userid | password | username | email | phone |
+--------+----------+----------+-------+-------+
| 110    | 123456   | 111110   | NULL  | NULL  |+--------+----------+----------+-------+-------+在创建时没设置为空
  表创建完成后
  当表中没记录 我要设置 让password为非空 SQL语句怎么写

解决方案 »

  1.   

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

  2.   

    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: 0mysql> 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>
      

  3.   


    改成整数:
    Alter table `你的表名` modify `password` int(11) NOT NULL; 改成字符串:
    Alter table `你的表名` modify `password` varchar(20) NOT NULL; 写法一样的