在 MySQL 中从 SHOW COLUMNS 中排除某些列?
mysqlmysqli database
让我们先创建一个演示表
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)