Reputation: 781
I want to get Create table script for an existing Table basically DDL from web UI or something similar to Show create table . I have googled couldn't find anything relevant
Upvotes: 18
Views: 41245
Reputation: 2195
Cool news! Launched today, now you can get the DDL from INFORMATION_SCHEMA.TABLES
Here is the example from Google Documentation:
SELECT
table_name, ddl
FROM
`bigquery-public-data`.census_bureau_usa.INFORMATION_SCHEMA.TABLES
WHERE
table_name="population_by_zip_2010"
Upvotes: 50
Reputation: 746
There is a Feature Request to have equivalent of SHOW CREATE TABLE
MySQL command. As you can see from the comment#2 from Elliott, it's not likely to be implemented. However you can "recreate a CREATE TABLE statement using INFORMATION_SCHEMA", for more detail, please check this public issue.
Upvotes: 4
Reputation: 1576
I don't think you can retrieve a CREATE
statement from an existing table in BigQuery, but you can do:
-Obtain the table schema:
bq show --schema --format=prettyjson [PROJECT_ID]:[DATASET].[TABLE] > ./schema.json
-Create a new table from the schema file:
bq mk --table --description [DESCRIPTION] [PROJECT_ID]:[DATASET].[TABLE] ./schema.json
You can review the additional settings for table creation here.
Upvotes: 19