---json
{
"canonical": ":howto:database:create_table_from_another",
"description": "This Howto will show you how to copy the data definition of a SQL table from another SQL table",
"low_quality_page": "false",
"name": "Table creation from another",
"page_id": "qotxtxkjlhw885z3nse6b",
"title": "How to create a table from the definition of another SQL table"
}
---
====== Tabli - How to create a table from the definition of another table ======
===== About =====
This [[..:howto|Howto]] will show you how to copy the [[docs:resource:structure|data definition]] of a [[docs:resource:table|SQL table]] from another [[docs:resource:table|SQL table]] by using the [[docs:tabli:data:create|Tabli table create command]].
This command does not copy the data. It just [[docs:op:create|create]] the structure (ie it performs a SQL ''CREATE'' statement). If you want to copy the data, use the [[docs:tabli:data:transfer|tabli data transfer command]] instead.
===== Steps =====
==== Prerequisites ====
You should have ''Tabulify'' installed on your computer.
[[howto:getting_started:1_install]]
==== Create a table from another table ====
Delete the target destination
tabli data drop --not-strict *@sqlite
The below command will create:
* the table ''tpcds_sales'' into the [[docs:connection:default|Sqlite Howto connection]]
* from the data definition of the [[docs:system:tpcds|tpcds]] ''store_sales'' table
* with the [[docs:tabli:data:create|tabli data create]] command.
tabli data create store_sales@tpcds tpcds_sales@sqlite
where:
* ''store_sales@tpcds'' is a [[docs:resource:data_selector|data selector]]
* and ''tpcds_sales@sqlite'' is a [[docs:resource:target_uri|target data URI]]
The list of data resources created
uri
------------------
tpcds_sales@sqlite
==== Check the metadata ====
Check the metadata with the [[docs:tabli:data:struct|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
==== Next ====
You can also create a table and its dependencies (foreign tables) at once with the [[docs:tabli:data:create|tabli data create command]].
\\
\\
[[tabli_create_table_with_dependencies|How to copy a star/snowflake schema ?]]