Exclude certain columns from SHOW COLUMNS in MySQL?



Let us first create a demo table

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)

Now you can check the description of table with the help of desc command. The query is as follows −

mysql> desc excludeCertainColumnsDemo;

The following is the output

+----------------+--------------+------+-----+---------+----------------+ | 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)

Here is the query to exclude certain columns from SHOW COLUMNS. You need to exclude the column 'StudentAge' and 'StudentMarks'. The query is as follows −

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

The following is the output

+----------------+--------------+------+-----+---------+----------------+ | 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)
Updated on: 2019-07-30T22:30:25+05:30

373 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements