mysql字段自动增长语法_MySQL中如何实现字段的自动增长?

创建表以及插入数据的操作如下,为什么id字段不能自动增长?怎么样才能让id自动增长?请高手指教!mysql>createtableuser(->idint(4)primarykeyauto_increment,->usernamevarchar(20)...

创建表以及插入数据的操作如下,为什么id字段不能自动增长?怎么样才能让id自动增长?请高手指教!

mysql> create table user(

-> id int(4) primary key auto_increment,

-> username varchar(20),

-> password varchar(20)

-> );

Query OK, 0 rows affected (0.13 sec)

mysql> desc user;

+----------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+----------------+

| id | int(4) | NO | PRI | NULL | auto_increment |

| username | varchar(20) | YES | | NULL | |

| password | varchar(20) | YES | | NULL | |

+----------+-------------+------+-----+---------+----------------+

3 rows in set (0.02 sec)

mysql> insert into user values('','admin','123456');

ERROR 1264 (22003): Out of range value adjusted for column 'id' at row 1

mysql> insert into user values(,'admin','123456');

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that

corresponds to your MySQL server version for the right syntax to use near ''admi

n','123456')' at line 1

mysql> insert into user values('admin','123456');

ERROR 1136 (21S01): Column count doesn't match value count at row 1

mysql> insert into user values('2','admin','123456');

Query OK, 1 row affected (0.02 sec)

mysql> insert into user values('5','test','55555');

Query OK, 1 row affected (0.02 sec)

mysql> select * from user;

+----+----------+----------+

| id | username | password |

+----+----------+----------+

| 2 | admin | 123456 |

| 5 | test | 55555 |

+----+----------+----------+

2 rows in set (0.00 sec)

mysql>

已经有人给我解决了!

http://community.csdn.net/Expert/topic/5219/5219952.xml?temp=.6816675

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值