Home » Bigquery » Tutorials » Create table like

BigQuery Create table like

Create table like statement creates an empty table copying the structure from another table. By default, the new table inherits partitioning, clustering, and options metadata from the source table

Create table like example

CREATE TABLE mydataset.New_Employee
    LIKE mydataset.Employee

Create table like override partitioning

CREATE TABLE mydataset.New_Employee
    LIKE mydataset.Employee
    Partition by Join_Date
    Cluster by Id, dept

Create table like with data

CREATE TABLE mydataset.New_Employee
    LIKE mydataset.Employee
    Partition by Join_Date
    Cluster by Id, dept
    as 
    select * from mydataset.Staff;

Explanation

The CREATE TABLE LIKE statement copies only the metadata of the source table. You can use the as query_statement clause to include data into the new table.

Syntax reference

{CREATE TABLE | CREATE TABLE IF NOT EXISTS | CREATE OR REPLACE TABLE}
[[project_name.]dataset_name.]table_name
LIKE [[project_name.]dataset_name.]source_table_name
[PARTITION BY partition_expression]
[CLUSTER BY clustering_column_list]
[OPTIONS(table_option_list)]
[AS query_statement]