English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

What are the different methods to check if a MySQL table exists?

Let's look at some methods to check if a table exists in MySQL.

Using SHOW

The SHOW command displays all tables.

SHOW tables;

This is the output.

+--------------------------+
| Tables_in_business       |
+--------------------------+
| addcheckconstraintdemo   |
| addcolumntable           |
| addconstraintdemo        |
| alphademo                |
| autoincrement            |
| autoincrementtable       |
| backticksymbol           |
| bookindexes              |
| chardemo                 |
| checkdemo                |
| clonestudent             |
| columnexistdemo          |
| columnvaluenulldemo      |
| commaseperatedemo        |
| dateadddemo              |
| deletedemo               |
| deleterecord             | 
| demo |
| demo |1                    |
| demo ascii |
| demo auto |
| demo bcrypt |
| demo empty and null |
| demo int |
| demo on replace |
| demo schema |
| demo where |
| distinct demo |
| duplicate book indexes |
| duplicate found |
| employee table |
| escape demo |
| exists row demo |
| find and replace demo |
| first table |
| foreign table |
| foreign table demo |
| function trigger demo |
| group demo |
| group demo |1               |
| if else demo |
| image demo |
| case sensitive demo |
| indexing demo |
| int |1demo |
| integer demo |
| latitude and longitude demo |
| limit offset demo |
| millisecond demo |
| modify column name demo |
| modify datatype |
| 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   |
| transactiondemo          |
| triggedemo               |
| trigger1                 |
| trigger2demo             |
| unsigneddemo             |
| updtable                 |
| usernameandpassworddemo       |
| varchardemo              |
| varchardemo1             |
| varchardemo2             |
| varcharurl               |
| wherecondition            |
| xmldemo                |
+--------------------------+
107 rows in set (0.15 sec)

Using LIKE to display a single table

This is the syntax.

SHOW TABLES LIKE 'yourTableName';

Now let's implement the above syntax in the following query.

mysql> SHOW TABLES LIKE 'tblstudent';

This is the output.

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