Home > Database > Mysql Tutorial > How to Count the Number of Tables in a Database

How to Count the Number of Tables in a Database

Patricia Arquette
Release: 2025-01-29 16:02:09
Original
451 people have browsed it

How to Count the Number of Tables in a Database

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.

PostgreSQL database

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>
Copy after login
If you need to query other modes, replace
    to the target mode name.
  • 'public'
  • mysql database

In mysql, you can also use view and filter according to the database name:

information_schema.tables

Please replace for your database name.
<code class="language-sql">SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = 'your_database_name';</code>
Copy after login
  • SQL Server database your_database_name
In SQL Server, you can use

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>
Copy after login
Sqlite database
  • In SQLite, you can use the number of
table statistical forms:

Oracle database

sqlite_master In Oracle database, you can use

view and filter according to the mode owner:
<code class="language-sql">SELECT COUNT(*)
FROM sqlite_master
WHERE type = 'table';</code>
Copy after login

Please 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 login
    Although 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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template