Analyzing MySQL database and data table exists

Analyzing MySQL database and data table exists


 

How to use SQL queries, database and data tables to determine whether there is?

 

1, it is determined whether there is a database

SQL query as follows:

the SELECT  *  
from information_schema.SCHEMATA 
 the WHERE SCHEMA_NAME =  ' need to find the database name ' ;

 

 Can be fuzzy query, SQL as follows:

the SELECT  *  
from information_schema.SCHEMATA 
 the WHERE SCHEMA_NAME like  ' part of the name% name of the database to be queried% ' ;

 

2, it is determined whether there is a data table

SQL query as follows:

SELECT  *  
from information_schema.tables 
 WHERE TABLE_NAME =  ' need to query the data table ' ;

 

Can be fuzzy query, SQL as follows:

the SELECT  *  
from information_schema.tables 
 the WHERE TABLE_NAME like  ' % part of the name need to query the database name% ' ;

 

Guess you like

Origin www.cnblogs.com/miracle-luna/p/12059270.html