注册 登录
编程论坛 MySQL论坛

建表时,如何让mysql标识列ID从1开始自动增长

ccii09 发布于 2007-07-25 16:07, 9773 次点击

create table aaa
(
ID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(50)
)

怎么样处理才能让ID自动增长,以后插入只需要insert into aaa ('asdfasdf')就可以了,请高手指点

8 回复
#2
lmhllr2007-07-25 19:22

举个例子吧:


CREATE TABLE `admin` (
  `aid` int(11) NOT NULL auto_increment,
  `name` char(50) default NULL,
  `pass` char(32) default NULL,
  `lastip` int(11) default NULL,
  `lastdate` int(11) default NULL,
  `gid` int(11) default NULL,
  PRIMARY KEY  (`aid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;


设置主键PRIMARY KEY (`aid`)然后auto_increment

[此贴子已经被作者于2007-7-25 19:24:30编辑过]

#3
fengxfu2007-07-28 22:28
不行啊,按二楼的做法建好表后,
insert into baio values('aaa');错误如下:
ERROR 1136 (21S01):Column count doesn't match value count at row 1

//////////////////////////用下边insert语句。。
insert into baio values(,'c');报错如下:
ERROR 1064 (42000):You hava an error in your SQL syntax; check the manual that corresponds to your MySql server version for the right syntax to use near ''c')' at line 1
#4
fengxfu2007-07-29 18:08

版主???这问题怎么解决????等。。。

#5
lmhllr2007-07-30 18:45

insert into baio values(NULL,'c');

#6
夜雨葬花魂2007-09-04 16:00
insert into baio (这里面不写自增列,写上要插入的字段名称) values(对应字段的值);
我喜欢这样写
个人习惯问题
#7
ConZhang2007-09-06 22:56
设置为autoincreament,就可以了!
#8
ConZhang2007-09-06 22:58
回复:(夜雨葬花魂)insert into baio (这里面不写自...
我也是这样的习惯!
#9
ai0_0jun2012-04-17 11:29
AUTO_INCREMENT 放在最后面描述 主键列。
create table biao(
    id int primary key not null AUTO_INCREMENT,
    name varchar(10) not null
);

insert into baio(name) values('张三');
insert into baio(name) values('李四');
insert into baio(name) values('王五');
insert into baio(name) values('郑六');
1