How to create a table from the definition of another SQL table


This Howto will show you how to copy the data definition of a SQL table from another SQL table by using the Tabli table create command.

This command does not copy the data. It just create the structure (ie it performs a SQL CREATE statement). If you want to copy the data, use the tabli data transfer command instead.



You should have Tabulify installed on your computer.

Learning Tabulify - Step 1 - Installation

Create a table from another table

The below command will create:

tabli data create store_sales@tpcds tpcds_sales@sqlite


The list of data resources created

Check the metadata

Check the metadata with the tabli data meta command

tabli data struct tpcds_sales@sqlite
Position   Column Name             Data Type   Primary Key   Not Null   Auto Increment   Description
--------   ---------------------   ---------   -----------   --------   --------------   -----------
1          ss_sold_date_sk         integer                   x          false
2          ss_sold_time_sk         integer                   x          false
3          ss_item_sk              integer     x                        false
4          ss_customer_sk          integer                   x          false
5          ss_cdemo_sk             integer                   x          false
6          ss_hdemo_sk             integer                   x          false
7          ss_addr_sk              integer                   x          false
8          ss_store_sk             integer                   x          false
9          ss_promo_sk             integer                   x          false
10         ss_ticket_number        integer     x                        false
11         ss_quantity             integer                   x          false
12         ss_wholesale_cost       numeric                   x          false
13         ss_list_price           numeric                   x          false
14         ss_sales_price          numeric                   x          false
15         ss_ext_discount_amt     numeric                   x          false
16         ss_ext_sales_price      numeric                   x          false
17         ss_ext_wholesale_cost   numeric                   x          false
18         ss_ext_list_price       numeric                   x          false
19         ss_ext_tax              numeric                   x          false
20         ss_coupon_amt           numeric                   x          false
21         ss_net_paid             numeric                   x          false
22         ss_net_paid_inc_tax     numeric                   x          false
23         ss_net_profit           numeric                   x          false


You can also create a table and its dependencies (foreign tables) at once with the tabli data create command.

How to copy a star/snowflake schema ?

Task Runner