Using Information schema to check if a MySQL table exists

by Rekha 2010-01-28 14:04:04

From MySQL 5.0 there is an information schema database which contains the information about the databases. This database can be used to determine various information, including whether or not a table exists in a given database in MySQL.

Syntax

SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = '[database name]'
AND table_name = '[table name]'


Example

SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = 'test'
AND table_name = 'test1';

Tagged in:

1129
like
0
dislike
0
mail
flag

You must LOGIN to add comments