MySQL 是否可以在向MySQL插入数据时跳过某些列?

MySQL 是否可以在向MySQL插入数据时跳过某些列?

如果您的第一列是AUTO_INCREMENT,则可以跳过该列并将值设置为NULL。让我们首先创建一个表 –

mysql> create table DemoTable
(
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   StudentFirstName varchar(100),
   StudentAge int
);
Query OK, 0 rows affected (0.60 sec)

使用插入命令将一些记录插入表中。这里,我们跳过了第一列,因为它是AUTO_INCREMENT –

mysql> insert into DemoTable values(NULL,'Robert',21);
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values(NULL,'Sam',22);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(NULL,'Bob',24);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(NULL,'Carol',20);
Query OK, 1 row affected (0.14 sec)

使用SELECT语句显示表中的所有记录 –

mysql> select * from DemoTable;

这将生成以下输出 –

+-----------+------------------+------------+
| StudentId | StudentFirstName | StudentAge |
+-----------+------------------+------------+
|         1 | Robert           |         21 |
|         2 | Sam              |         22 |
|         3 | Bob              |         24 |
|         4 | Carol            |         20 |
+-----------+------------------+------------+
4 rows in set (0.00 sec)

阅读更多:MySQL 教程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程