
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Check if table exist without using “select from” in MySQL?
We can achieve this with the help of SHOW command. Firstly, I will use my database with the help of USE command −
mysql> USE business; Database changed
We are in the “business” database now. After that, we can check that how many tables are available for this database. The query is as follows −
mysql> SHOW tables;
The following is the output
+------------------------+ | Tables_in_business | +------------------------+ | addcolumntable | | autoincrement | | autoincrementtable | | bookindexes | | chardemo | | clonestudent | | columnvaluenulldemo | | dateadddemo | | deletedemo | | deleterecord | | demo | | demo1 | | demoascii | | demoauto | | demobcrypt | | demoemptyandnull | | demoint | | demoonreplace | | demoschema | | distinctdemo | | duplicatebookindexes | | duplicatefound | | employeetable | | existsrowdemo | | findandreplacedemo | | firsttable | | foreigntable | | foreigntabledemo | | groupdemo | | groupdemo1 | | incasesensdemo | | int1demo | | intdemo | | latandlangdemo | | limitoffsetdemo | | milliseconddemo | | modifycolumnnamedemo | | modifydatatype | | moneydemo | | moviecollection | | mytable | | nonasciidemo | | nthrecorddemo | | nulldemo | | nullwithselect | | pasthistory | | presenthistory | | primarytable | | primarytable1 | | primarytabledemo | | rownumberdemo | | rowstranspose | | rowstransposedemo | | secondtable | | sequencedemo | | smallintdemo | | spacecolumn | | student | | tblfirst | | tblstudent | | tbluni | | textdemo | | texturl | | trailingandleadingdemo | | transcationdemo | | unsigneddemo | | updtable | | varchardemo | | varchardemo1 | | varchardemo2 | | varcharurl | | whereconditon | +------------------------+ 72 rows in set (0.03 sec)
Alternate ways by which we can check whether a table exist or not without using SELECT statement is shown below.
The syntax is as follows −
SHOW tables like ‘yourTableName’;
Now, I am applying the above query to check whether the table exist or not for my database “business”.
The query is as follows −
mysql> SHOW tables like 'tblstudent';
The following is the output
+---------------------------------+ | Tables_in_business (tblstudent) | +---------------------------------+ | tblstudent | +---------------------------------+ 1 row in set (0.00 sec)
Look at the output above, the table ‘tblstudent’ is visible in my database. The case when table does not exist is as follows −
mysql> SHOW tables like 'sampledemo'; Empty set (0.00 sec)
- Related Articles
- MySQL SELECT from table A that does not exist in table B using JOINS?
- Select from table where value does not exist with MySQL?
- Different methods to check if a MySQL table exist?
- How to select from MySQL table A that does not exist in table B?
- How to check if a column exist in a MySQL table?
- Can we select second largest record from a table without using LIMIT clause in MySQL?
- How to check if a table exists in MySQL and create if it does not already exist?
- Select rows from a MySQL table and display using IN()
- MySQL query to check if multiple rows exist?
- SELECT last entry without using LIMIT in MySQL?
- How do I detect if a table exist in MySQL?
- How to select sum or 0 if no records exist in MySQL?
- Insert values in a table by MySQL SELECT from another table in MySQL?
- Get table names using SELECT statement in MySQL?
- How to select all the data from a table using MySQL in Python?

Advertisements