Different methods to check if a MySQL table exist?


Let us see some of the ways to check if a table exist in MySQL or not.

Using SHOW

The SHOW command displays all the tables.

SHOW tables;

Here is the output.

+--------------------------+
| Tables_in_business       |
+--------------------------+
| addcheckconstraintdemo   |
| addcolumntable           |
| addconstraintdemo        |
| alphademo                |
| autoincrement            |
| autoincrementtable       |
| backticksymbol           |
| bookindexes              |
| chardemo                 |
| checkdemo                |
| clonestudent             |
| columnexistdemo          |
| columnvaluenulldemo      |
| commaseperatedemo        |
| dateadddemo              |
| deletedemo               |
| deleterecord             | 
| demo                     |
| demo1                    |
| demoascii                |
| demoauto                 |
| demobcrypt               |
| demoemptyandnull         |
| demoint                  |
| demoonreplace            |
| demoschema               |
| demowhere                |
| distinctdemo             |
| duplicatebookindexes     |
| duplicatefound           |
| employeetable            |
| escapedeom               |
| existsrowdemo            |
| findandreplacedemo       |
| firsttable               |
| foreigntable             |
| foreigntabledemo         |
| functiontriggersdemo     |
| groupdemo                |
| groupdemo1               |
| ifelsedemo               |
| imagedemo                |
| incasesensdemo           |
| indexingdemo             |
| int1demo                 |
| intdemo                  |
| latandlangdemo           |
| limitoffsetdemo          |
| milliseconddemo          |
| modifycolumnnamedemo     |
| modifydatatype           |
| moneydemo                |
| moviecollection          |
| multipleindexdemo        |
| multiplerecordwithvalues |
| mytable                  |
| mytable1                 |
| nextpreviousdemo         | 
| nonasciidemo             |
| nthrecorddemo            |
| nulldemo                 |
| nullwithselect           |
| numbercolumndemo         |
| ondemo                   |
| pasthistory              |
| presenthistory           |
| primarytable             |
| primarytable1            |
| primarytabledemo         |
| qutesdemo                |
| rowcountdemo             |
| rownumberdemo            |
| rowstranspose            |
| rowstransposedemo        |
| secondtable              |
| sequencedemo             |
| smallintdemo             |
| sortingvarchardemo       |
| spacecolumn              |
| student                  |
| tbldemotrail             |
| tblf                     |
| tblfirst                 |
| tblfunctiontrigger       |
| tblifdemo                |
| tblp                     |
| tblselectdemo            |
| tblstudent               |
| tbluni                   |
| tblupdatelimit           |
| textdemo                 |
| texturl                  |
| timestampdemo            |
| trailingandleadingdemo   |
| transcationdemo          |
| triggedemo               |
| trigger1                 |
| trigger2demo             |
| unsigneddemo             |
| updtable                 |
| usernameandpassworddemo  |
| varchardemo              |
| varchardemo1             |
| varchardemo2             |
| varcharurl               |
| whereconditon            |
| xmldemo                  |
+--------------------------+
107 rows in set (0.15 sec)

Using LIKE to display a single table

Here is the syntax.

SHOW TABLES LIKE 'yourTableName';

Let us now implement the above syntax in the following query.

mysql> SHOW TABLES LIKE 'tblstudent';

Here is the output.

+---------------------------------+
| Tables_in_business (tblstudent) |
+---------------------------------+
| tblstudent                      |
+---------------------------------+
1 row in set (0.00 sec)

Updated on: 26-Jun-2020

100 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements