JBa
JBa

Reputation: 5509

How can I write a sql query to check if a particular table exists in a database?

I know how to use queries but I've never had to use one for this particular tasks .. I know about the SHOW TABLES; command .. How can I write a query to check if a particular table exists in a MYSQL database .. For example , a query that checks if table MEMBERS exists in database called USERS ??

Upvotes: 1

Views: 914

Answers (2)

Gil Peretz
Gil Peretz

Reputation: 2429

Searching Table:

select * from information_schema.tables where table_name like '%MEMBERS%'

Searching Column:

select * from information_schema.columns where table_name like '%COLUMN%'

Upvotes: 2

Russ Cam
Russ Cam

Reputation: 125538

You can use INFORMATION_SCHEMA.TABLES

USE USERS;
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'MEMBERS'

Upvotes: 2

Related Questions