Wikibooks: Informatics Practices for Class XI (CBSE)/Simple queries

Note Based on the [[Language chapter]] of the [[MySQL book]]. = Browsing the databases = The following SQL commands provide information about the databases located on the current server. The INFORMATION SCHEMA table containing this information is SCHEMATA. The mysqlshow command line tool can be used...

Full description

Bibliographic Details
Format: Book
Language:English
Subjects:
DML
Online Access:https://en.wikibooks.org/wiki/Informatics_Practices_for_Class_XI_(CBSE)/Simple_queries
Description
Summary:Note Based on the [[Language chapter]] of the [[MySQL book]]. = Browsing the databases = The following SQL commands provide information about the databases located on the current server. The INFORMATION SCHEMA table containing this information is SCHEMATA. The mysqlshow command line tool can be used instead. You can t show databases if the server has been started with theā€”skip all databases option. If you don t have the SHOW DATABASES privilege you ll only see databases on which you have some permissions. = List databases = Show all databases SHOW DATABASES The SCHEMA keywords can be used in place of DATABASES. MySQL doesn t support standard SQL SCHEMAs so SCHEMA is a synonym of database. It has been added for compatibility with other DBMS s. =Add a filter on the databases names= SHOW DATABASES LIKE pattern The LIKE operator here works as in normal SELECTs or DML statements. So you can list all databases whose name starts with my SHOW DATABASES LIKE MY% =Add complex filters= You can add more complex filters using the WHERE clause SHOW DATABASES WHERE (conditions) WHERE clause allows you to use regular expressions operators string functions or other useful expressions to filter the records returned by SHOW DATABASES. = List tables and views = The following SQL commands provide information about the tables and views contained in a database. The INFORMATION SCHEMA tables containing this information are `TABLES` and `VIEWS`. Since the following statements provide very little information about views if you need to get metadata about them you ll probably prefer to query the VIEWS table. The mysqlshow command line tool can be used instead. =Show all tables= USE database SHOW TABLES SHOW TABLES FROM database The 2 forms shown above are equivalent. =Apply a filter= You can apply a filter to the tables names to show only tables whose name match a pattern. You can use the LIKE operatore as you do in SELECTs or in the DML statements SHOW TABLES LIKE `pattern` Also you can apply a more complex filter to any column returned ...