Exclude certain columns from SHOW COLUMNS in MySQL?

MySQLMySQLi Database

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)
raja
Published on 01-Apr-2019 08:59:56
Advertisements