---json
{
"aliases": [
{ "path": ":howto:sqlite:tabul_create_table_script" }
],
"canonical": ":howto:database:table_create_from_script",
"description": "This Howto will show you how to create a SQL table with a SQL file that contains a ''CREATE'' SQL statement",
"low_quality_page": "false",
"name": "Create a table From a CREATE statement",
"page_id": "56k9l707e3p1y037kmu44"
}
---
====== Tabulify - How to create a table with a CREATE Sql statement file ======
===== About =====
This [[..:howto|Howto]] will show you how to create a [[docs:resource:sql_table|SQL table]] with a SQL file that contains a ''CREATE'' SQL statement with the [[docs:tabul:data:create|Tabul table create command]].
===== Steps =====
==== Prerequisites ====
You should have ''Tabulify'' installed on your computer: [[howto:getting_started:1_install]]
==== The CREATE table statement ====
Delete the target destination
tabul data drop --no-strict-selection *@sqlite
We will execute the below [[:docs:resource:sql_ddl|SQL DDL Script]] that is located in the [[docs:connection:howto|howto connection]].
-- Create the foo table statement
create table foo (
bar integer
)
==== The data create command ====
With the [[docs:tabul:data:create|tabul data create]] command, if you use a [[docs:flow:runtime_selector|runtime selector]] as first argument, the selected [[docs:resource:runtime|script]] are executed.
To execute the previous SQL script, the below the command should be executed:
tabul data create '(create_foo.sql@howto)@sqlite'
# The quotes are only mandatory in bash because parenthesis are a bash token (ie subshell)
where:
* ''data create'' is the [[docs:tabul:data:create|data create]] command
* ''(create_foo.sql@howto)@sqlite'' is a [[docs:flow:runtime_selector|runtime selector]] that select the ''create_foo.sql'' in the [[docs:connection:howto|howto]] connection and executes it in the [[docs:connection:howtos|Sqlite howtos connection]]
List of runtime executed
runtime_data_uri exit_code count latency data_uri error_message
----------------------------- --------- ----- ------- ------------------------------------------------------------- -------------
(create_foo.sql@howto)@sqlite 0 1 0.31s execute/20251110-204850-409-pipe-anonymous/create_foo.log@tmp
==== Check the metadata ====
Check the metadata with the [[docs:tabul:data:describe|tabul data meta]] command
tabul data describe foo@sqlite
Structure of the resource foo@sqlite
position name type precision scale primary_key nullable autoincrement comment
-------- ---- ------- --------- ----- ----------- -------- ------------- -------
1 bar integer 0 0 x
==== Next ====
You can also create a table and its dependencies (foreign tables) at once with the [[docs:tabul:data:create|tabul data create command]].
\\
\\
[[howto:sql_schema:create_table_with_dependencies|How to copy a star/snowflake schema ?]]