PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
MySQL有AUTO_INCREMENT关键字来执行自动递增。AUTO_INCREMENT的起始值为1,这是默认值。每个新记录都会递增1。
要在MySQL中获取下一个自动递增的id,我们可以使用MySQL的last_insert_id()函数或者SELECT语句中的auto_increment。
创建一个表,其中“id”为自增。
mysql> create table NextIdDemo -> ( -> id int auto_increment, -> primary key(id) -> ); Query OK, 0 rows affected (1.31 sec)
将记录插入表中。
mysql> insert into NextIdDemo values(1); Query OK, 1 row affected (0.22 sec) mysql> insert into NextIdDemo values(2); Query OK, 1 row affected (0.20 sec) mysql> insert into NextIdDemo values(3); Query OK, 1 row affected (0.14 sec)
显示所有记录。
mysql> select *from NextIdDemo;
以下是输出结果。
+----+ | id | +----+ | 1 | | 2 | | 3 | +----+ 3 rows in set (0.04 sec)
我们在上面插入了3条记录。因此,下一个id必须是4。
以下是了解下一个id的语法。
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = "yourDatabaseName" AND TABLE_NAME = "yourTableName"
以下是查询。
mysql> SELECT AUTO_INCREMENT -> FROM information_schema.TABLES -> WHERE TABLE_SCHEMA = "business" -> AND TABLE_NAME = "NextIdDemo";
这里是显示下一个自动增量的输出。
+----------------+ | AUTO_INCREMENT | +----------------+ | 4 | +----------------+ 1 row in set (0.25 sec)
已抢6799个
抢已抢91613个
抢已抢14418个
抢已抢50597个
抢已抢190558个
抢已抢86253个
抢