在 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)
广告