且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mysql如何创建表自动递增?

更新时间:2023-02-03 16:28:07

看看下面的链接.它应该可以工作,但是您需要添加ENGINE = MyISAM;在您声明的末尾.
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html [ ^ ]

对于InnoDB,请点击此处:
http://dev.mysql.com/doc/refman/5.1/zh_/innodb-auto-increment-handling.html [ ^ ]

还请检查一下:
http://dev.mysql.com/doc/refman/5.1/zh_CN/server-sql-mode.html#sqlmode_no_auto_value_on_zero [ ^ ]

祝你好运!
Have a look at the link below. It should work but you need to add ENGINE=MyISAM; at the end of your statement.
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html[^]

For InnoDB look here:
http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-handling.html[^]

Also check this out:
http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html#sqlmode_no_auto_value_on_zero[^]

Good luck!




您可以使用以下查询,
Hi,

You can use following query,
CREATE TABLE employee_data
(
emp_id int NOT NULL AUTO_INCREMENT,
f_name varchar(30),
l_name varchar(20),
age int,
salary int,
PRIMARY KEY (emp_id)
)

ALTER TABLE employee_data AUTO_INCREMENT=1;


插入查询将为
INSERT INTO Persons (f_name,l_name,age,salary) VALUES (''Brian'',''lara'',25,5000)
您也可以通过
检查最后插入的ID mysql_insert_id()

希望这会有所帮助.


Insert query will be
INSERT INTO Persons (f_name,l_name,age,salary) VALUES (''Brian'',''lara'',25,5000)
Also you can check last inserted id by
mysql_insert_id()

Hope this will help.