Skip to main content

Create an object component template

Object component templates extract schema objects (tables, views, stored procedures, functions, triggers) from the live database and version them in your workspace. This guide shows the minimum template, then the options you'll reach for.

Before you start

  • You've created a workspace and connected it to a database.
  • You know which kind of object you're generating for: table, view, procedure, function, trigger, or DDL trigger.
  • You've decided whether you want one component per object (simple, explicit) or one template that discovers objects (see Generate components in bulk).

The minimum template

Create an XML file under your workspace's templates/ folder:

<?xml version="1.0" encoding="utf-8"?>
<ObjectComponent Category="functions" Name="GetAccountBalance" Schema="dbo">
<SchemaObject Name="GetAccountBalance" Type="Function"/>
</ObjectComponent>

Three things going on:

  1. <ObjectComponent>. The root. Category groups this in the UI; Name is the component filename.
  2. <SchemaObject>. The object being extracted. Name is the object's name in the database; Type tells DataStar how to render the CREATE script.
  3. Schema on the root. The database schema/owner to extract from.

Save the file, refresh the workspace, and DataStar will offer to extract dbo.GetAccountBalance as a component.

The Type attribute

<SchemaObject> supports these types:

TypeWhat gets extracted
TableCREATE TABLE with columns, constraints, indexes (optionally), triggers
ViewCREATE VIEW with the full definition
ProcedureCREATE PROCEDURE with body
FunctionCREATE FUNCTION (scalar or table-valued)
TriggerCREATE TRIGGER (DML trigger)
DdlTriggerCREATE TRIGGER ... ON DATABASE ... (DDL trigger)

Pick one per <SchemaObject>. A single template can have several <SchemaObject> elements if you want to group related objects, but most templates have just one.

Common options

Options tune what's included in the generated script. Add them as <Option> elements before <SchemaObject>:

<ObjectComponent Category="functions" Name="GetAccountBalance" Schema="dbo">
<Option Name="Permissions" Value="True"/>
<Option Name="CreateOrAlter" Value="True"/>
<SchemaObject Name="GetAccountBalance" Type="Function"/>
</ObjectComponent>
OptionEffect
PermissionsInclude GRANT / DENY statements for the object
IndexesInclude index definitions (tables and indexed views)
CreateOrAlterGenerate CREATE OR ALTER instead of CREATE (SQL Server 2016+)
LineFormattingControl blank-line handling in the extracted body
ServerVersionPin generated syntax to a specific target (e.g. 11.0 for SQL Server 2012)

Deployment ordering

If your object depends on other objects (a view on a table, a procedure on a function), control deployment order with <Deployment Weight>:

<ObjectComponent Category="views" Name="AccountSummary" Schema="dbo">
<SchemaObject Name="AccountSummary" Type="View"/>
<Deployment Weight="300"/>
</ObjectComponent>

Lower weights deploy first. A conventional scheme:

WeightObject kind
100Tables
200Functions
280Stored procedures
300Views
400Triggers
500Data components

Pick once, apply consistently across templates.

One template, many components

For anything where you'd otherwise end up with 100 near-identical templates (every view, every stored procedure), use a <DynamicQuery> to discover targets from the database itself:

<ObjectComponent Category="views" Name="${filename}" Schema="${schema}">
<SchemaObject Name="${name}" Type="View"/>
<DynamicQuery><![CDATA[
SELECT TABLE_SCHEMA AS '${schema}',
'[' + LOWER(TABLE_SCHEMA) + '].[' + LOWER(TABLE_NAME) + ']' AS '${filename}',
TABLE_NAME AS '${name}'
FROM INFORMATION_SCHEMA.VIEWS
]]></DynamicQuery>
<Deployment Weight="300"/>
</ObjectComponent>

One template generates a component per view in the database. See Generate components in bulk for the full pattern.

Verifying the output

Once saved, extract a component and inspect the generated script:

  • It should be a complete CREATE … (or CREATE OR ALTER) statement, nothing missing.
  • Permissions, if enabled, appear at the end.
  • Index definitions (for tables) appear after the column list.

If the script looks truncated or out of order, try the options above; most gaps are a missing Permissions="True" or a ServerVersion that's too old for the feature being emitted.

See also