如何在 MySQL 中显示表中的列名(不包括部分列名)?

mysqlmysqli database更新于 2025/11/7 23:40:17

要排除部分列名,请使用 NOT IN。

首先我们创建一个表 −

mysql> create table DemoTable780 (
   CustomerId int,
   CustomerName varchar(100),
   CustomerAge int,
   CustomerCountryName varchar(100),
   isMarried tinyint(1)
);
Query OK, 0 rows affected (0.47 sec)

这是排除结果的查询 −

mysql> select group_concat(column_name) from `information_schema`.`COLUMNS` m
   where
   table_schema = 'web' and
   table_name = 'DemoTable780' and
   column_name not in ('CustomerId','CustomerCountryName')
   group by table_schema,table_name;

这将产生以下输出 -

+------------------------------------+
| group_concat(column_name)          |
+------------------------------------+
| CustomerName,CustomerAge,isMarried |
+------------------------------------+
1 row in set (0.01 sec)

相关文章


有用资源