MySQL 如何排除SHOW COLUMNS中的某些列

MySQL 如何排除SHOW COLUMNS中的某些列

首先,我们创建一个演示表:

mysql> create table excludeCertainColumnsDemo
    -> (
    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    -> StudentName varchar(100),
    -> StudentAge int,
    -> StudentMarks int,
    -> StudentAddress varchar(200)
    -> );
Query OK, 0 rows affected (0.50 sec)

然后您可以使用desc命令查看表的描述信息。查询语句如下:

mysql> desc excludeCertainColumnsDemo;

以下是输出结果:

+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| StudentId      | int(11)      | NO   | PRI | NULL    | auto_increment |
| StudentName    | varchar(100) | YES  |     | NULL    |                |
| StudentAge     | int(11)      | YES  |     | NULL    |                |
| StudentMarks   | int(11)      | YES  |     | NULL    |                |
| StudentAddress | varchar(200) | YES  |     | NULL    |                |
+----------------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)

下面是从SHOW COLUMNS中排除某些列的查询语句。您需要排除“StudentAge”和“StudentMarks”列。查询语句如下:

mysql> SHOW COLUMNS FROM excludeCertainColumnsDemo WHERE Field NOT IN ('StudentAge', 'StudentMarks');

以下是输出结果:

+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| StudentId      | int(11)      | NO   | PRI | NULL    | auto_increment |
| StudentName    | varchar(100) | YES  |     | NULL    |                |
| StudentAddress | varchar(200) | YES  |     | NULL    |                |
+----------------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

阅读更多:MySQL 教程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程