This feature may not be available by default and might need to be enabled upon request. Please contact your account manager for more information.
Table Templates are currently available for the following Databases:
Snowflake
Google BigQuery
Databricks
-
Azure Synapse
What are table templates?
Table templates allow you to accelerate the build of tables that would follow a consistent pattern and reduce design time.
A typical use case for this would be creating a data vault 2.0 table based on another table already in your model (see "How to use Table Templates" later in this article for further instructions).
Table templates allow you to automate things like:
Table naming standards - by adding common patterns to the names of tables and columns. An example of this is prefixing dimension tables with the prefix "Dim_".
Table colors - if you're working with Data Vault 2.0, you can ensure the objects (e.g., hubs, sats, and links) are always created with the standard colors.
System columns - consistently add system columns like load_date or valid_from.
Transformation logic - generate the SELECT statement for the new object from its source tables. Templates work with both SQL and dbt, and can join multiple tables in a single statement (see "Generating SQL and dbt logic" later in this article).
How do table templates differ from column templates?
SqlDBM offers users the possibility to create column and table templates. However, several differences in their behavior should be considered.
Column templates are added to an existing table, while table templates create a new table.
Column templates are binding, and future changes to them will affect the tables that use them. Table templates are non-binding, and changes to them do not affect existing tables that have been created as a result.
Users can benefit from the best of both worlds by assigning column templates through table templates.
Table templates in action
Default table templates
There are five out-of-the-box templates to help get you started:
hub (default)
link (default)
satellite (default)
type 2 dimension (default)
view (default) - Snowflake only
The default templates are for reference and cannot be removed or edited by users. However, they can be cloned and adjusted to your exact specifications.
Example code for "2 dimension (default)" Table Template
name: type 2 dimension (default)
physicalName: dim_${parentPhysicalName}
inheritIdentifiersAs: pk
inheritAttributes: true
generateRelationship: none
primaryColumns:
- name: from_dts
dataType: timestamp_ntz(9)
nullable: false
position: last
defaultColumns:
- name: to_dts
dataType: timestamp_ntz(9)
position: first
- name: load_dts
dataType: timestamp_ntz(9)
position: last
Creating a table template
Table templates can be created from scratch or by duplicating one that already exists.
Duplicating a table template
To duplicate a table template, do the following:
Right-click or select the "three-dot" menu on the template you wish to duplicate
From the options provided, select "Duplicate"
-
The duplicated template will now be named
_Clone
Creating a new table template
When creating a new table template, a default YAML showing all template properties is included. This default should be adjusted by removing any unnecessary properties and setting the values for those that remain. See the "Editing a table template" section for more on this.
To create a new template:
Right-click on the "Table templates" header or any existing table template, or click on their respective "three-dot" menus
Select "Create new"
A new table template will be created and added to the bottom of your table template list
The only required property for a template is the "name." All other properties are optional or have defined defaults.
Complete YAML properties reference
The following sections describe all properties supported by table templates for each type of project.
Snowflake
# ============================================================================= # Object Template # ----------------------------------------------------------------------------- # Defines a reusable object (table, view, materialized view, or dynamic table) # that can be applied to new objects in a project. Properties marked #required # must be supplied; all others fall back to the indicated #default. # ============================================================================= # ----------------------------------------------------------------------------- # Template metadata # ----------------------------------------------------------------------------- name: 'unique template name' # required description: 'My template description' materialization: table | dynamicTable | view | materializedView # default: table # ----------------------------------------------------------------------------- # Object-level properties # ----------------------------------------------------------------------------- schema: mySchemaName | '${parentSchema}' # default: '${parentSchema}' physicalName: '${objectPhysicalName}' # default: '${objectPhysicalName}' logicalName: 'My logical name' # default: '${objectLogicalName}' useQuotes: true | false # default: false comment: 'My DDL comment' color: color label name # must reference the label, not the color flags: ['flag1', 'flag2', ...] snowflakeTags: - name: myTag value: myVal isTransient: true | false dataRetention: 1 # in days # Type of relationship auto-generated to the parent object. generateRelationship: none | physical | VFK | VJ | VDEP # default: none for table # VDEP for view, MV, dynamic table # A list is also accepted: one of physical | VFK | VJ, plus VDEP - e.g. [VFK, VDEP] # How identifier columns are inherited from the parent object. inheritIdentifiersAs: pk | non-pk | none # default: non-pk inheritAttributes: true | false # default: true # Names of column templates to apply to this object. columnTemplates: ['my_col_temp1', 'my_col_temp2', '...'] # Layer in which the object is visible. visibility: physical&logical | physicalOnly | logicalOnly # default: physical&logical # Generate SQL or dbt logic for tables generateSqlLogic: true | false # default: true for view, materializedView, dynamicTable; false for table generateDbtLogic: true | false # default: false sourceQualification: full | schema | name # default: schema. SQL section only # ----------------------------------------------------------------------------- # Columns # ----------------------------------------------------------------------------- # Two column groups are supported and share the same property set: # primaryColumns - the object's keys and required attributes # defaultColumns - additional standard attributes (e.g. audit fields) # ----------------------------------------------------------------------------- primaryColumns: - name: 'myColumn' # required logicalName: 'My logical name' dataType: '' # required, e.g. VARCHAR(50), NUMBER(18,0) comment: 'My DDL comment' nullable: true | false # default: false unique: true | false # default: false useQuotes: true | false # default: false default: '' isVPK: true | false # mark as Virtual Primary Key VBK: 'VBK name' # Virtual Business Key; reuse the same # name across columns for compound keys # SQL expression for view / MV / dynamic-table columns. # Escape single quotes per YAML rules. logic: "'SQL formula'" identity: true | false # default: false sequence: 'mySeq' visibility: physical&logical | physicalOnly | logicalOnly # default: physical&logical flags: ['flag1', 'flag2', ...] snowflakeTags: - name: myTag value: myVal position: first | last # default: first defaultColumns: - name: 'myColumn' # required logicalName: 'My logical name' dataType: '' # required comment: 'My DDL comment' nullable: true | false # default: false unique: true | false # default: false useQuotes: true | false # default: false default: '' isVPK: true | false VBK: 'VBK name' # reuse the same name for compound keys # SQL expression for view / MV / dynamic-table columns. logic: "'SQL formula'" identity: true | false # default: false sequence: 'mySeq' visibility: physical&logical | physicalOnly | logicalOnly # default: physical&logical flags: ['flag1', 'flag2', ...] snowflakeTags: - name: myTag value: myVal position: first | last # default: first # ----------------------------------------------------------------------------- # Post-script # ----------------------------------------------------------------------------- postScript: 'Any SQL;' # appended after the object DDL # ============================================================================= # Materialization-specific properties # ----------------------------------------------------------------------------- # Each block below applies only to the indicated materialization type(s) # and is ignored for all others. # ============================================================================= # --- View --- recursive: true | false # default: false changeTracking: true | false # default: false # --- Materialized view --- clusterBy: 'cluster by value' # default: empty dataMetricSchedule: type: unspecified | interval | cron # default: unspecified expression: 'interval or cron expression' # ignored when type = unspecified # --- View and materialized view (shared) --- copyGrants: true | false # default: false secure: true | false # default: false # --- Dynamic table --- targetLag: type: Downstream | Specify # default: Downstream specifyLag: 50 # default: empty specifyInterval: Seconds | Minutes | Hours | Days # default: Seconds warehouse: myWH # default: empty initializationWarehouse: myInitWh # default: empty initializeOn: Create | Schedule # default: Create refreshMode: Auto | Full | Incremental # default: Auto dataRetention: 3 # days, default: empty maxDataExtension: 4 # days, default: empty # ============================================================================= # Template variables # ----------------------------------------------------------------------------- # Can be used as values anywhere in this template. # # ${objectPhysicalName} Default physical name for a new object in the # project, respecting naming conventions. # ${parentPhysicalName} Physical name of the parent object when the # template is created from one; otherwise blank. # ${parentLogicalName} Logical name of the parent object when applicable; # otherwise blank. # ${parentSchema} Schema of the parent object when applicable; # otherwise blank. # =============================================================================Google BigQuery
name: 'unique template name' #required description: 'My template description' schema: mySchemaName | '${parentSchema}' #default: '${parentSchema}' physicalName: '${objectPhysicalName}' #default: '${objectPhysicalName}' logicalName: 'My logical name' #default: '${objectLogicalName}' comment: 'My DDL comment' color: color label name # must reference the label, not the color flags: ['flag1', 'flag2', ...] visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. expiresAt: '1970-01-01 00:00:00 UTC' #optional expirationDays: #optional partitionFilter: true | false #default: false collation: 'inherit_from_dataset' | 'binary' | 'und:ci' #default: inherit_from_dataset generateRelationship: none | physical | VFK | VJ | VDEP #default: none # A list is also accepted: one of physical | VFK | VJ, plus VDEP - e.g. [VFK, VDEP] inheritIdentifiersAs: pk | non-pk | none #default: non-pk inheritAttributes: true | false #default: true columnTemplates: ['my_col_temp1', 'my_col_temp2', 'etc.'] # Generate SQL or dbt logic for tables generateSqlLogic: true | false # default: false for table; true for view-type materializations, where available generateDbtLogic: true | false # default: false sourceQualification: full | schema | name # default: schema. SQL section only primaryColumns: - name: 'myColumn' #required logicalName: 'My logical name' dataType: '' #required comment: 'My DDL Comment' nullable: true | false #default: false unique: true | false #default: false default: '' collation: 'inherit_from_table' | 'binary' | 'und:ci' #default: inherit_from_table roundingMode: 'none' visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. flags: ['flag1', 'flag2', ...] #default: none position: first | last #default: first defaultColumns: - name: 'myColumn' #required logicalName: 'My logical name' dataType: '' #required comment: 'My DDL Comment' nullable: true | false #default: false unique: true | false #default: false default: '' collation: 'inherit_from_table' | 'binary' | 'und:ci' #default: inherit_from_table roundingMode: 'none' visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. flags: ['flag1', 'flag2', ...] #default: none position: first | last #default: first # The following variables can also be used in template values # # ${objectPhysicalName} - the default name for a new table in a given project, respecting naming conventions # ${parentPhysicalName} - the physical name when creating the template from a parent object, otherwise blank # ${parentLogicalName} - the logical name when creating the template from a parent object, otherwise blank # ${parentSchema} - the schema when creating the template from a parent object, otherwise blankAzure Synapse
name: 'unique template name' #required description: 'My template description' schema: mySchemaName | '${parentSchema}' #default: '${parentSchema}' physicalName: '${objectPhysicalName}' #default: '${objectPhysicalName}' logicalName: 'My logical name' #default: '${objectLogicalName}' comment: 'My DDL comment' visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. color: color label name # must reference the label, not the color flags: ['flag1', 'flag2', ...] generateRelationship: none | physical | VFK | VJ | VDEP #default: none # A list is also accepted: one of physical | VFK | VJ, plus VDEP - e.g. [VFK, VDEP] inheritIdentifiersAs: pk | non-pk | none #default: non-pk inheritAttributes: true | false #default: true columnTemplates: ['my_col_temp1', 'my_col_temp2', 'etc.'] # Generate SQL or dbt logic for tables generateSqlLogic: true | false # default: false for table; true for view-type materializations, where available generateDbtLogic: true | false # default: false sourceQualification: full | schema | name # default: schema. SQL section only primaryColumns: - name: 'myColumn' #required logicalName: 'My logical name' dataType: '' #required collation: 'collationValue' comment: 'My DDL Comment' nullable: true | false #default: false unique: true | false #default: false default: 'current_date()' visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. flags: ['flag1', 'flag2', ...] position: first | last #default: first defaultColumns: - name: 'myColumn' #required logicalName: 'My logical name' dataType: '' #required collation: 'Cyrillic_General_CI_AS' comment: 'My DDL Comment' nullable: true | false #default: false unique: true | false #default: false default: 'value' visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. flags: ['flag1', 'flag2', ...] position: first | last #default: first indexes: - indexName: 'indexName' indexType: 'unique' | 'index' #default: index generateAsConstraint: true | false #default: true members: - 'columnName1' - 'columnName2' description: 'Any text' structureOptions: 'clusteredColumnstoreIndex' | 'heap' | 'clusteredIndex' # default 'clusteredColumnstoreIndex' structureMember: 'columnName' distributionOptions: 'roundRobin'| 'hash' | 'replicate' #default 'roundRobin' distributionMember: 'columnName' partitionOptions: partitionMember: 'columnName' partitionValues: - partitionValue range: right | left #default left postScript: 'Any SQL;' # The following variables can also be used in template values # # ${objectPhysicalName} - the default name for a new table in a given project, respecting naming conventions # ${parentPhysicalName} - the physical name when creating the template from a parent object, otherwise blank # ${parentLogicalName} - the logical name when creating the template from a parent object, otherwise blank # ${parentSchema} - the schema when creating the template from a parent object, otherwise blankDatabricks
name: 'unique template name' #required description: 'My template description' # 'external' value is supported for 'materialization' parameter materialization: 'table' #default: 'table' ('table' | 'external') schema: mySchemaName | '${parentSchema}' #default: '${parentSchema}' physicalName: '${objectPhysicalName}' #default: '${objectPhysicalName}' logicalName: 'My logical name' #default: '${objectLogicalName}' comment: 'My DDL comment' visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. color: color label name # must reference the label, not the color flags: ['flag1', 'flag2', ...] generateRelationship: none | physical | VFK | VJ | VDEP #default: none # A list is also accepted: one of physical | VFK | VJ, plus VDEP - e.g. [VFK, VDEP] inheritIdentifiersAs: pk | non-pk | none #default: non-pk inheritAttributes: true | false #default: true # Generate SQL or dbt logic for tables generateSqlLogic: true | false # default: false for table; true for view-type materializations, where available generateDbtLogic: true | false # default: false sourceQualification: full | schema | name # default: schema. SQL section only primaryColumns: - name: 'myColumn' #required logicalName: 'My logical name' dataType: '<datatype>' #required comment: 'My DDL Comment' nullable: true | false #default: false unique: true | false #default: false default: '<default>' #or expression: 'LEFT(col1,2)' identity: true | false #default: false visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. flags: ['flag1', 'flag2', ...] position: first | last #default: first defaultColumns: - name: 'myColumn' #required logicalName: 'My logical name' dataType: '<datatype>' #required comment: 'My DDL Comment' nullable: true | false #default: false unique: true | false #default: false default: '<default>' #or expression: 'LEFT(col1,2)' identity: true | false #default: false visibility: physical&logical | physicalOnly | logicalOnly #default: physical&logical. flags: ['flag1', 'flag2', ...] position: first | last #default: first # 'fileFormat' is mandatory for external tables fileFormat: 'Avro' | 'Csv' | 'Delta' | 'Json' | 'Orc' | 'Parquet' | 'Text' #default 'none', mandatory if materialization: 'external' # 'location' parameter is added location: '/data/location_path' #String, if materialization: 'external' (mandatory), esle (optional) tblProperties: - name: 'delta.columnMapping.mode' #'delta.columnMapping.mode' property to make the alter scripts work correctly value: 'name' # (string, required), default 'name' # The following variables can also be used in template values # # ${objectPhysicalName} - the default name for a new table in a given project, respecting naming conventions # ${parentPhysicalName} - the physical name when creating the template from a parent object, otherwise blank # ${parentLogicalName} - the logical name when creating the template from a parent object, otherwise blank # ${parentSchema} - the schema when creating the template from a parent object, otherwise blankEditing a table template
(Non-default) templates can be modified using the YAML editor.
Right-click or select the "three-dot" menu on the table template you want to modify
Select "Edit"
-
Use the YAML template editor to modify the contents to:
Add or remove properties
Modify the property values
Leave comments (using the hash "#" sign)
The editor contains two tabs: YAML Script and Warnings & Errors
YAML Script is where you will edit the template.
Warnings & Errors is where you'll be notified of any warnings and errors.
Remember that YAML rules require all properties to have a value. Properties without a value (e.g., "myProperty: ") will result in an error and invalidate the template.
Inconsistencies like unrecognized property names or values will result in a warning and will be skipped during object creation. They will not invalidate the template.
The following variables can be used as part of property values
${objectPhysicalName} - The system-generated physical name for a new SqlDBM object, respecting existing naming conventions. This is the same name that a new object would take when created on a diagram, following project naming conventions (typically, "table_n").
${parentPhysicalName} - The physical name of the parent if creating the template from an existing object. Otherwise, blank
${parentLogicalName} - The logical name of the parent if creating the template from an existing object. Otherwise, blank.
${parentSchema} - The schema name of the parent if creating the template from an existing object. Otherwise, blank.
Inheriting parent table columns
Table templates can be used to generate tables from scratch or using a parent table. When creating from a parent table, the following properties can be used to determine which columns will be inherited and the order in which they will appear.
inheritIdentifiersAs: (string, pk | non-pk | none , default: non-pk) - determines whether or not identifiers (PKs) are inherited by the resulting table. A value of "pk" means that they will also be primary in the resulting table, while "non-pk" will add them as only attributes; "none" will exclude them entirely.
inheritAttributes: (boolean, default: true ) - determines whether or attributes (non-PK columns) are inherited by the resulting table.
position: (string, first | last) - inherited columns (PKs and attributes) are position-neutral and will be inherited in the order that they appear in the parent table. However, template columns (defined in the PK and attribute section of the template) can be assigned a position value of "first" or "last" to indicate the order in which they appear in their respective section. Refer to the "Dimension (default)" template to see an example of how this property is used.
Renaming a table template
To rename an existing table template:
Right-click or select the "three-dot" menu on the template you would like to rename
Select "Edit"
The YAML script editor will open
-
Update the value in the "Name" field
example: enter "I have a new name"
-
will result in the template being shown in the database explorer as:
-
Deleting a table template
To delete an existing table template, follow the steps below. (Default templates can not be deleted).
Right-click or select the "three-dot" menu on the template you would like to delete
Select "Delete"
Generating SQL and dbt logic
A table template can also write the SELECT logic for the object it creates. The logic is built from the source objects you select when you apply the template, so you start from a runnable query instead of a blank editor. It works for SQL and for dbt, and when you select more than one source table, the templates join them for you.
Three template properties control this:
generateSqlLogic: (boolean, default: true for view, materializedView, and dynamicTable; false for table) - generates a SQL SELECT statement that references the source objects by name.
generateDbtLogic: (boolean, default: false) - generates the same statement in dbt form, referencing the sources with
{{ ref() }}or{{ source() }}according to each source's dbt type. The new object is classified as a dbt Model.sourceQualification: (string, full | schema | name, default: schema) - sets how source objects are named in the SQL logic: fully qualified, schema.object, or object name only. It does not affect dbt logic.
Both generateSqlLogic and generateDbtLogic can be true in the same template. In that case, both versions are generated from the same sources, joins, and columns.
To also record how the new object relates to its sources, use generateRelationship. It accepts a single value or a list that combines one relationship type (physical, VFK, or VJ) with a dependency (VDEP), for example
[VFK, VDEP].How the logic is built
Each source object becomes a CTE, in alphabetical order by object name. A last CTE named
finalselects the columns of the new object.When there are multiple sources,
finaljoins them on the relationships that already exist between them in your model: physical foreign keys, virtual relationships with column pairs, and virtual joins.Where two sources have no relationship, the join is written with
<<join_column>>placeholders for you to complete.If the same column name exists in more than one source, every occurrence is kept and renamed with its object name (for example,
customer_customer_idandorders_customer_id), following your project naming convention.Template columns that have a logic value are added to
finalin their defined position.
Example
The following template creates a view with both SQL and dbt logic:
name: customer_orders_model materialization: view generateSqlLogic: true generateDbtLogic: true generateRelationship: [VFK, VDEP] inheritIdentifiersAs: non-pk inheritAttributes: true defaultColumns: - name: etl_src dataType: varchar(50) logic: "'salesforce'" position: firstApplied to the tables sales.customer and sales.orders, which are related on customer_id, it generates this SQL logic:
WITH customer AS ( SELECT customer_id, customer_name, email FROM sales.customer ) , orders AS ( SELECT order_id, customer_id, order_date, total FROM sales.orders ) , final AS ( SELECT 'salesforce' AS etl_src, customer.customer_id AS customer_customer_id, customer.customer_name, customer.email, orders.order_id, orders.customer_id AS orders_customer_id, orders.order_date, orders.total FROM customer INNER JOIN orders ON customer.customer_id = orders.customer_id ) SELECT * FROM final ;The dbt logic has the same structure, written in dbt style, with the sources referenced through dbt. In this example, customer is a dbt source and orders is a dbt model:
with customer as ( select customer_id, customer_name, email from {{ source('raw_sales', 'customer') }} ), orders as ( select order_id, customer_id, order_date, total from {{ ref('orders') }} ), final as ( ... from customer inner join orders on customer.customer_id = orders.customer_id ) select * from finalWhere to find the generated logic
Open the new object in edit mode and select the Logic tab. It has a SQL section and a dbt section.
For views, materialized views, and dynamic tables, the SQL section is the object definition and is included in DDL.
For tables, the SQL section is stored with the table and is not included in DDL by default.
The dbt section is never included in DDL. It is used for the dbt model file.
Logic is generated once, when the object is created. You can edit it freely afterwards; later changes to the template do not overwrite it.
Using table templates
Table templates can be used to create a new table from scratch or from an existing parent table.
Create a new table from an existing table
Using a template of your choice, you can create a table from an existing parent.
Identify the parent table you wish to reference on the diagram or the explorer panel
Right-click on the table and navigate to the "Create from template" menu
Select the template that should be applied
The resulting table is added to the active diagram
Create a new object from multiple tables
You can apply a template to several tables at once to create one object that combines them.
Select two or more tables on the diagram
Right-click on the selection and navigate to the "Create from template" menu
Select the template that should be applied
The resulting object is added to the active diagram, with the columns inherited from every selected table
If the template generates SQL or dbt logic, the selected tables are joined in that logic (see "Generating SQL and dbt logic").
Create a new table from scratch
Users can create an independent new table using a template in one of two ways.
From the diagram
Right-click on the diagram canvas
Select "create from template"
Select the template to use
The resulting table is added to the active diagram
From the top-bar menu
"Add table" icon from the top bar menu
Select the template to use
The resulting table is added to the active diagram
See also: