Database management work often requires statistics in the number of tables in the database, which is very practical in database audit, documentation or maintenance. Most relational database management systems (RDBMS) provide convenient methods to count the number of forms by system directory or information mode. Here are several statistical methods for commonly used databases.
In PostgreSQL, you can use the
view query number of forms in specific mode:
information_schema.tables
<code class="language-sql">SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';</code>
'public'
In mysql, you can also use view and filter according to the database name:
information_schema.tables
<code class="language-sql">SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'your_database_name';</code>
SQL Server database your_database_name
Directory view statistics to all the number of tables in the current database:
This query is suitable for the database you currently connected. sys.tables
<code class="language-sql">SELECT COUNT(*) FROM sys.tables;</code>
Sqlite databasetable statistical forms:
- In SQLite, you can use the number of
Oracle database view and filter according to the mode owner:
sqlite_master
In Oracle database, you can use<code class="language-sql">SELECT COUNT(*) FROM sqlite_master WHERE type = 'table';</code>Copy after loginPlease replace to the corresponding mode name.
all_tables
Summary<code class="language-sql">SELECT COUNT(*) FROM all_tables WHERE owner = 'YOUR_SCHEMA_NAME';</code>Copy after loginAlthough the methods of storing metadata in each database system are different, querying the system directory or information mode is a common method for obtaining the table detailed information. With these query statements, you can quickly count the number of tables in any database.
YOUR_SCHEMA_NAME
If you need more detailed help for specific databases, please tell me the database type you use!
The above is the detailed content of How to Count the Number of Tables in a Database. For more information, please follow other related articles on the PHP Chinese website!