在 MySQL 中创建具有手动 AUTO_INCREMENT 起始值的表查询?

mysqlmysqli database更新于 2024/1/9 3:18:00

首先我们创建一个表 −

mysql> create table DemoTable1907
   (
   UserId int NOT NULL AUTO_INCREMENT,
   UserName varchar(20),
   UserAge int,
   UserCountryName varchar(20),
   PRIMARY KEY(UserId)
   )ENGINE=MyISAM,AUTO_INCREMENT=100;
Query OK, 0 rows affected (0.00 sec)

使用 insert 命令在表中插入一些记录 −

mysql> insert into DemoTable1907(UserName,UserAge,UserCountryName) values('Chris',26,'US');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1907(UserName,UserAge,UserCountryName) values('David',38,'UK');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1907(UserName,UserAge,UserCountryName) values('John',28,'AUS');
Query OK, 1 row affected (0.00 sec)

使用 select 语句显示表中的所有记录 −

mysql> select * from DemoTable1907;

这将产生以下输出 −

+--------+----------+---------+-----------------+
| UserId | UserName | UserAge | UserCountryName |
+--------+----------+---------+-----------------+
|    100 | Chris    | 26      | US              |
|    101 | David    | 38      | UK              |
|    102 | John     | 28      | AUS             |
+--------+----------+---------+-----------------+
3 rows in set (0.00 sec)

相关文章