GCP BigQuery Cheat Sheet
SQL syntax and CLI/Python client reference for querying, loading, and managing data warehouses in Google BigQuery.
2 PagesIntermediateFeb 18, 2026
Basic Query
Standard SQL query against a public dataset.
sql
SELECT name, COUNT(*) AS totalFROM `bigquery-public-data.usa_names.usa_1910_2013`WHERE state = 'CA'GROUP BY nameORDER BY total DESCLIMIT 10;
bq CLI Commands
Load data and run queries from the command line.
bash
bq mk my_dataset # Create datasetbq load --source_format=CSV \ my_dataset.my_table gs://my-bucket/data.csv \ name:STRING,age:INTEGERbq query --use_legacy_sql=false \ 'SELECT COUNT(*) FROM my_dataset.my_table'bq show my_dataset.my_table # Table schema/infobq rm -t my_dataset.my_table # Delete table
Python Client
Run a query using the google-cloud-bigquery library.
python
from google.cloud import bigqueryclient = bigquery.Client()query = """ SELECT name, total FROM `my_dataset.my_table` ORDER BY total DESC LIMIT 10"""for row in client.query(query).result(): print(row.name, row.total)
Key Concepts
Key key concepts to know.
- Dataset- Top-level container for tables and views within a project
- Partitioned Table- Physically divided by a column (often date) to reduce bytes scanned
- Clustered Table- Sorted by column(s) to speed up filtering within partitions
- Slot- Unit of computational capacity used to execute queries
- Materialized View- Precomputed query results automatically refreshed for faster reads
Pricing & Performance Tips
Key pricing & performance tips to know.
- On-Demand Pricing- Billed per TB of data scanned by the query
- SELECT *- Avoid it; BigQuery is columnar and scans only referenced columns, so selecting fewer columns cuts cost
- --dry_run- bq CLI flag to estimate bytes scanned before running a query
- Partition Pruning- Filtering on the partition column skips scanning irrelevant partitions
Pro Tip
Always filter on the partitioning column (e.g. WHERE _PARTITIONDATE or a date column) in WHERE clauses — it lets BigQuery prune unscanned partitions, which directly reduces both query cost and latency.
Was this cheat sheet helpful?
Explore Topics
#GCPBigQuery#GCPBigQueryCheatSheet#CloudComputing#Intermediate#BasicQuery#BqCLICommands#PythonClient#KeyConcepts#Databases#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance