设置了auto_increment的列怎么添加数据?

解决方案 »

  1.   

    mysql> create table t_Fire1949(id int auto_increment primary key, col int);
    Query OK, 0 rows affected (0.44 sec)mysql> -- 方法一,不指定:
    mysql> insert into t_Fire1949(col) values (100);
    Query OK, 1 row affected (0.06 sec)mysql> select * from t_Fire1949;
    +----+------+
    | id | col  |
    +----+------+
    |  1 |  100 |
    +----+------+
    1 row in set (0.00 sec)mysql> -- 方法二,用 Null:
    mysql> insert into t_Fire1949(id,col) values (null,200);
    Query OK, 1 row affected (0.05 sec)mysql> select * from t_Fire1949;
    +----+------+
    | id | col  |
    +----+------+
    |  1 |  100 |
    |  2 |  200 |
    +----+------+
    2 rows in set (0.00 sec)mysql> -- 方法三, 用0:
    mysql> insert into t_Fire1949(id,col) values (0,200);
    Query OK, 1 row affected (0.05 sec)mysql> select * from t_Fire1949;
    +----+------+
    | id | col  |
    +----+------+
    |  1 |  100 |
    |  2 |  200 |
    |  3 |  200 |
    +----+------+
    3 rows in set (0.00 sec)mysql> -- 方法四, 自行指定:
    mysql> insert into t_Fire1949(id,col) values (100,200);
    Query OK, 1 row affected (0.03 sec)mysql> select * from t_Fire1949;
    +-----+------+
    | id  | col  |
    +-----+------+
    |   1 |  100 |
    |   2 |  200 |
    |   3 |  200 |
    | 100 |  200 |
    +-----+------+
    4 rows in set (0.00 sec)mysql>
      

  2.   

    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html