如何在MySQL的auto_increment列中插入自己的值?
您可以借助INSERT语句来实现此目的,即,您可以像普通插入一样简单地将其插入。语法如下-
INSERT INTO yourTableName (yourIdColumnName,yourColumnName) values(value1,'value2');Let us first create a table:
mysql> create table InsertValueInAutoIncrement
-> (
-> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> UserName varchar(20)
-> );
现在,您可以使用insert命令在表中插入一些记录。在这里,我们还将为auto_increment字段UserId插入我们自己的值。查询如下-
mysql> insert into InsertValueInAutoIncrement(UserName) values('John');mysql> insert into InsertValueInAutoIncrement(UserName) values('Carol');
mysql> insert into InsertValueInAutoIncrement(UserName) values('Sam');
mysql> insert into InsertValueInAutoIncrement(UserName) values('Bob');
mysql> insert into InsertValueInAutoIncrement(UserId,UserName) values(100,'Maxwell');
mysql> insert into InsertValueInAutoIncrement(UserName) values('James');
mysql> insert into InsertValueInAutoIncrement(UserId,UserName) values(1000,'Larry');
使用select语句显示表中的所有记录。查询如下-
mysql> select *from InsertValueInAutoIncrement;
下表是-
+--------+----------+| UserId | UserName |
+--------+----------+
| 1 | John |
| 2 | Carol |
| 3 | Sam |
| 4 | Bob |
| 100 | Maxwell |
| 101 | James |
| 1000 | Larry |
+--------+----------+
7 rows in set (0.00 sec)
以上是 如何在MySQL的auto_increment列中插入自己的值? 的全部内容, 来源链接: utcz.com/z/335314.html