How to List Tables in BigQuery

Galaxy Glossary

How do I quickly list all tables in a BigQuery dataset?

RETURN the names and metadata for all tables within a BigQuery dataset.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Description

Table of Contents

What is the fastest way to list tables in BigQuery?

Run a simple SELECT against the INFORMATION_SCHEMA.TABLES view or use the bq ls CLI command. Both return table names instantly without scanning data.

Which SQL syntax lists tables in a dataset?

Use SELECT table_name FROM `project_id.dataset_id.INFORMATION_SCHEMA.TABLES` WHERE table_type = 'BASE TABLE';. Replace project_id and dataset_id with your own values.

Can I include views and materialized views?

Yes. Omit the table_type filter or adjust it to 'VIEW' or 'MATERIALIZED VIEW' to retrieve those object types.

How do I list tables with row counts and sizes?

Add row_count and size_bytes columns from INFORMATION_SCHEMA.TABLE_STORAGE. Join them on table_name for richer metadata without full table scans.

Why use INFORMATION_SCHEMA over bq ls?

SQL is portable and works inside workflows, while bq ls is convenient in terminals and scripts. INFORMATION_SCHEMA also lets you filter, sort, or join for advanced reporting.

Best practice: reference tables by full path

Always qualify tables with project and dataset (project.dataset.table). This avoids ambiguity and cross-region errors, especially in multi-project environments.

Example: audit ecommerce tables

The query below lists all base tables in ecommerce dataset, then joins storage metadata to display row counts and sizes.

WITH tables AS (
SELECT table_name
FROM `myproj.ecommerce.INFORMATION_SCHEMA.TABLES`
WHERE table_type = 'BASE TABLE'
)
SELECT t.table_name,
s.row_count,
ROUND(s.size_bytes/1024/1024, 2) AS size_mb
FROM tables t
JOIN `myproj.ecommerce.__TABLES__` s
ON t.table_name = s.table_id
ORDER BY size_mb DESC;

How do I script this in the CLI?

bq ls --project_id=myproj --format=prettyjson ecommerce

The --format flag outputs machine-readable JSON for automation.

Why How to List Tables in BigQuery is important

How to List Tables in BigQuery Example Usage


-- List all base tables in an ecommerce dataset
SELECT table_name
FROM   `shop_prod.ecommerce.INFORMATION_SCHEMA.TABLES`
WHERE  table_type = 'BASE TABLE'
ORDER  BY table_name;

How to List Tables in BigQuery Syntax


-- SQL approach
SELECT table_name
FROM   `project_id.dataset_id.INFORMATION_SCHEMA.TABLES`
WHERE  table_type = 'BASE TABLE';

-- Include views
SELECT table_name, table_type
FROM   `project_id.dataset_id.INFORMATION_SCHEMA.TABLES`;

-- CLI approach
bq ls [-n max_results] [--format=prettyjson] project_id:dataset_id

Common Mistakes

Frequently Asked Questions (FAQs)

Does listing tables cost money?

No. INFORMATION_SCHEMA and bq ls read metadata, not data, so the operation is free.

Can I list tables across all datasets?

Yes. Query region-level INFORMATION_SCHEMA e.g., `region-us.INFORMATION_SCHEMA.SCHEMATA` first, then loop or join to gather tables.

How do I filter by creation date?

Include the creation_time column: `WHERE DATETIME(table_creation_time) > '2024-01-01'` to list newer tables only.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.