<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/DDL+Metadata">DDL Metadata</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        correcting constraint examples, still need to update RR diagrams<br />
    </div>
        <br/>
                         <h4>Changes (5)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >CREATE FOREIGN TABLE Customer (id integer PRIMARY KEY, firstname varchar(25), lastname varchar(25),  dob timestamp); <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >CREATE FOREIGN TABLE Order (id integer PRIMARY KEY, customerid integer, saledate date, amount <span class="diff-changed-words">decimal(25,4)<span class="diff-added-chars"style="background-color: #dfd;">,</span></span> CONSTRAINT <span class="diff-added-words"style="background-color: #dfd;">CUSTOMER_FK</span> FOREGIN KEY(customerid) REFERENCES Customer(id)); <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >CONSTRAINTS are same as one can define on RDBMS. <br>{code:SQL|title=Example of CONSTRAINTs} <br></td></tr>
            <tr><td class="diff-changed-lines" >CREATE VIEW CustomerOrders (name varchar(50),  saledate date, amount <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">decimal CONSTRAINT</span> <span class="diff-added-words"style="background-color: #dfd;">decimal,</span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">   INDEX (name, amount) <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">   CONSTRAINT EXAMPLE_INDEX INDEX (name, amount), <br></td></tr>
            <tr><td class="diff-changed-lines" >ACCESSPATTERN <span class="diff-changed-words">(name)<span class="diff-added-chars"style="background-color: #dfd;">,</span></span> <br></td></tr>
            <tr><td class="diff-unchanged" >   PRIMARY KEY ... <br>{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>Starting with Teiid 8.0, a VDB can define models/schemas using DDL. Here is small example of how one can define a View inside the "-vdb.xml" file. See the &lt;metadata&gt; element under &lt;model&gt;.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example to show view definition</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;model visible = "true" type = "VIRTUAL" name = "customers"&gt;
     &lt;metadata type = "DDL"&gt;&lt;![CDATA[
              CREATE VIEW PARTS (
                   PART_ID integer PRIMARY KEY,
                   PART_NAME varchar(255),
                   PART_COLOR varchar(30),
                   PART_WEIGHT varchar(255)
               ) AS
                  select a.id as PART_ID, a.name as PART_NAME, b.color as PART_COLOR, b.weight as PART_WEIGHT from modelA.part a, modelB.part b where a.id = b.id
     ]]&gt;
     &lt;metadata&gt;
&lt;/model&gt;
</pre>
</div></div>

<p>Another complete DDL based example is at the end of this section.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Metadata Repositories</b><br />The declaration of metadata using DDL, NATIVE, or DDL-FILE is supported out of the box, however the <em>MetadataRepository</em> interface allows users to plug-in their own metadata facilities. For example, you can write a Hibernate based store that can feed the necessary metadata. See <a href="/author/display/TEIID/Custom+Metadata+Repository" title="Custom Metadata Repository">Custom Metadata Repository</a> for more information.</td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Metadata for Source Models</b><br />The DDL based schema is not constrained to be defined only for the view models.</td></tr></table></div>

<h1><a name="DDLMetadata-BNFnotationfortheMetadata"></a>BNF notation for the Metadata</h1>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Grammar Reference</b><br />The full grammar for DDL can be found in the <a href="/author/display/TEIID/BNF+for+SQL+Grammar" title="BNF for SQL Grammar">BNF for SQL Grammar</a>.</td></tr></table></div>


<h2><a name="DDLMetadata-CreateFOREIGNTable"></a>Create FOREIGN Table</h2>

<p>A <em>FOREIGN</em> table is table that is defined on PHYSICAL model that represents a real relational table in source databases like Oracle, SQLServer etc. For relational databases, Teiid has capability to automatically retrieve the database schema information upon the deployment of the VDB, if one like to auto import the existing schema. However, user can use below FOREIGN table semantics, when they would like to explicitly define tables on PHYSICAL models or represent non-relational data as relational in custom translators.</p>


<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_table.jpg?version=1&amp;modificationDate=1344460117000" style="border: 1px solid black" /></span></p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example:Create Foreign Table(Created on PHYSICAL model)</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CREATE FOREIGN TABLE Customer (id integer PRIMARY KEY, firstname varchar(25), lastname varchar(25),  dob timestamp);

CREATE FOREIGN TABLE Order (id integer PRIMARY KEY, customerid integer, saledate date, amount decimal(25,4), CONSTRAINT CUSTOMER_FK FOREGIN KEY(customerid) REFERENCES Customer(id));
</pre>
</div></div>


<h2><a name="DDLMetadata-CreateView"></a>Create View</h2>

<p>A view is a virtual table. A view contains rows and columns,like a real table. The fields in a view are fields from one or more real tables from the source or other view models. They can also be expressions made up multiple columns, or aggregated columns. When column definitions are not defined on the view table, they will be derived from the projected columns of the view's select transformation that is defined after the <em>AS</em> keyword.</p>

<p>You can add functions, JOIN statements and WHERE clauses to a view data as if the data were coming from one single table.</p>

<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_view.jpg?version=1&amp;modificationDate=1344460136000" style="border: 1px solid black" /></span></p>


<p><b>TABLE/VIEW OPTIONS</b>: (the below are well known options, any others properties defined will be considered as extension metadata)</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Data Type or Allowed Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> UUID </td>
<td class='confluenceTd'> string <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> Unique identifier for View </td>
</tr>
<tr>
<td class='confluenceTd'> MATERIALIZED </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> Defines if a table is materialized </td>
</tr>
<tr>
<td class='confluenceTd'> MATERIALIZED_TABLE </td>
<td class='confluenceTd'> 'table.name' </td>
<td class='confluenceTd'> If this view is being materialized to a external database, this defines the name of the table that is being materialized to </td>
</tr>
<tr>
<td class='confluenceTd'> CARDINALITY </td>
<td class='confluenceTd'> int <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> Costing information. Number of rows in the table. Used for planning purposes </td>
</tr>
<tr>
<td class='confluenceTd'> UPDATABLE </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> Defines if the view is allowed to update or not </td>
</tr>
<tr>
<td class='confluenceTd'> ANNOTATION </td>
<td class='confluenceTd'> string <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> Description of the view </td>
</tr>
</tbody></table>
</div>



<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example:Create View Table(Created on VIRTUAL model)</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CREATE VIEW CustomerOrders (name varchar(50),  saledate date, amount decimal) OPTIONS (CARDINALITY 100, ANNOTATION 'Example')
  AS
  SELECT concat(c.firstname, c.lastname) as name, o.saledate as saledate, o.amount as amount FROM Customer C JOIN Order o ON c.id = o.customerid;
</pre>
</div></div>
<p><br class="atl-forced-newline" /></p>

<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_column.jpg?version=1&amp;modificationDate=1344460038000" style="border: 1px solid black" /></span></p>

<p><b>COLUMN OPTIONS</b>: (the below are well known options, any others properties defined will be considered as extension metadata)</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Data Type or Allowed Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> UUID </td>
<td class='confluenceTd'> string <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> A unique identifier for the column </td>
</tr>
<tr>
<td class='confluenceTd'> NAMEINSOURCE </td>
<td class='confluenceTd'> string <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> If this is a column name on the FOREIGN table, this value represents name of the column in source database, if omitted the column name is used when querying for data against the source </td>
</tr>
<tr>
<td class='confluenceTd'> CASE_SENSITIVE </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> SELECTABLE </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> TRUE when this column is available for selection from the user query </td>
</tr>
<tr>
<td class='confluenceTd'> UPDATABLE </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> Defines if the column is updatable.&nbsp; Defaults to true if the view/table is updatable. </td>
</tr>
<tr>
<td class='confluenceTd'> SIGNED </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> CURRENCY </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> FIXED_LENGTH </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> SEARCHABLE </td>
<td class='confluenceTd'> 'SEARCHABLE'&#124;'UNSEARCHABLE'&#124;'LIKE_ONLY'&#124;'ALL_EXCEPT_LIKE' </td>
<td class='confluenceTd'> column searchability, usually dictated by the data type </td>
</tr>
<tr>
<td class='confluenceTd'> MIN_VALUE </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> MAX_VALUE </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> CHAR_OCTET_LENGTH </td>
<td class='confluenceTd'> integer </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> ANNOTATION </td>
<td class='confluenceTd'> string <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> NATIVE_TYPE </td>
<td class='confluenceTd'> string <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> RADIX </td>
<td class='confluenceTd'> integer </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> NULL_VALUE_COUNT </td>
<td class='confluenceTd'> integer </td>
<td class='confluenceTd'> costing information. Number of NULLS in this column </td>
</tr>
</tbody></table>
</div>


<h3><a name="DDLMetadata-CONSTRAINTS"></a>CONSTRAINTS</h3>

<p>Constraints can be defined on table/view to define indexes and relationships to other tables/views. This information is used by the Teiid optimizer to plan queries or use the indexes in materialization tables to optimize the access to the data.</p>

<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_constraint.jpg?version=1&amp;modificationDate=1344460067000" style="border: 1px solid black" /></span></p>

<p>CONSTRAINTS are same as one can define on RDBMS.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example of CONSTRAINTs</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CREATE VIEW CustomerOrders (name varchar(50),  saledate date, amount decimal, 
   CONSTRAINT EXAMPLE_INDEX INDEX (name, amount),
   ACCESSPATTERN (name),
   PRIMARY KEY ...
</pre>
</div></div>

<h3><a name="DDLMetadata-INSTEADOFTRIGGERS"></a>INSTEAD OF TRIGGERS</h3>

<p>A view comprising multiple base tables must use an INSTEAD OF trigger to support inserts, updates and deletes that reference data in the tables. Based on the select transformation's complexity some times INSTEAD OF TRIGGERS are automatically provided for the user when "UPDATABLE" OPTION on the view is set to "TRUE". However, using the CREATE TRIGGER mechanism user can provide/override the default behaviour.</p>

<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_trigger.jpg?version=1&amp;modificationDate=1344460126000" style="border: 1px solid black" /></span></p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example:Define instead of trigger on View</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CREATE TRIGGER ON CustomerOrders INSTEAD OF INSERT AS
   FOR EACH ROW
   BEGIN ATOMIC
   INSERT INTO Customer (...) VALUES (NEW.value ...);
   END
</pre>
</div></div>

<h2><a name="DDLMetadata-CreateProcedure%2FFunction"></a>Create Procedure/Function</h2>

<p>Using the below syntax, user can define a</p>
<ul>
        <li>Source Procedure ("CREATE FOREIGN PROCEDURE") - a stored procedure in source</li>
        <li>Source Function ("CREATE FOREIGN FUNCTION") - A function that is supported by the source, where Teiid will pushdown to source instead of evaluating in Teiid engine</li>
        <li>Virtual Procedure ("CREATE VIRTUAL PROCEDURE") - Similar to stored procedure, however this is defined using the Teiid's Procedure language and evaluated in the Teiid's engine.</li>
        <li>Function/UDF ("CREATE VIRTUAL FUNCTION") - A user defined function, where user can define the calling semantics using below, however the function implementation is defined using a JAVA Class.<a href="/author/pages/createpage.action?spaceKey=TEIID&amp;title=1&amp;linkCreation=true&amp;fromPageId=20316193" class="createlink">1</a></li>
</ul>


<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_procedure.jpg?version=1&amp;modificationDate=1344460107000" style="border: 1px solid black" /></span></p>

<p><b>Variable Argument Support</b><br/>
Instead of using just an IN parameter, the last non result parameter can be declared VARIADIC to indicate that it can be repeated 0 or more times.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example:Vararg procedure</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">CREATE FOREIGN PROCEDURE proc (x integer, VARIADIC z integer) returns (x string);</pre>
</div></div>

<p><b>FUNCTION OPTIONS</b>:(the below are well known options, any others properties defined will be considered as extension metadata)</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Data Type or Allowed Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> UUID </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> unique Identifier </td>
</tr>
<tr>
<td class='confluenceTd'> NAMEINSOURCE </td>
<td class='confluenceTd'> If this is source function/procedure the name in the physical source, if different from the logical name given above </td>
</tr>
<tr>
<td class='confluenceTd'> ANNOTATION </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> Description of the function/procedure </td>
</tr>
<tr>
<td class='confluenceTd'> CATEGORY </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> Function Category </td>
</tr>
<tr>
<td class='confluenceTd'> DETERMINISM </td>
<td class='confluenceTd'><ul>
        <li>NONDETERMINISTIC</li>
        <li>COMMAND_DETERMINISTIC</li>
        <li>SESSION_DETERMINISTIC</li>
        <li>USER_DETERMINISTIC</li>
        <li>VDB_DETERMINISTIC</li>
        <li>DETERMINISTIC</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> NULL-ON-NULL </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
</tr>
<tr>
<td class='confluenceTd'> JAVA_CLASS </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> Java Class that defines the method in case of UDF </td>
</tr>
<tr>
<td class='confluenceTd'> JAVA_METHOD </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> The Java method name on the above defined java class for the UDF implementation </td>
</tr>
<tr>
<td class='confluenceTd'> VARARGS </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> Indicates that the last argument of the function can be repeated 0 to any number of times. default false. It is more proper to use a VARIADIC parameter. </td>
</tr>
<tr>
<td class='confluenceTd'> AGGREGATE </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> Indicates the function is a user defined aggregate function.  Properties specific to aggregates are listed below. </td>
</tr>
</tbody></table>
</div>


<p>Note that NULL-ON-NULL, VARARGS, and all of the AGGREGATE properties are also valid relational extension metadata properties that can be used on source procedures marked as functions.  See also <a href="/author/display/TEIID/Source+Supported+Functions" title="Source Supported Functions">Source Supported Functions</a> for creating FOREIGN functions that are supported by a source.</p>

<p><b>AGGREGATE FUNCTION OPTIONS</b>:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Data Type or Allowed Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> ANALYTIC </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> indicates the aggregate function must be windowed.  default false. </td>
</tr>
<tr>
<td class='confluenceTd'> ALLOWS-ORDERBY </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> indicates the aggregate function supports an ORDER BY clause.  default false </td>
</tr>
<tr>
<td class='confluenceTd'> ALLOWS-DISTINCT </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> indicates the aggregate function supports the DISTINCT keyword.  default false </td>
</tr>
<tr>
<td class='confluenceTd'> DECOMPOSABLE </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> indicates the single argument aggregate function can be decomposed as agg(agg&#40;x) ) over subsets of data.  default false </td>
</tr>
<tr>
<td class='confluenceTd'> USES-DISTINCT-ROWS </td>
<td class='confluenceTd'> 'TRUE'&#124;'FALSE' </td>
<td class='confluenceTd'> indicates the aggregate function effectively uses distinct rows rather than all rows.  default false </td>
</tr>
</tbody></table>
</div>


<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Providing the JAR libraries</b><br />If you have defined a UDF (virtual) function, then it must be accompanied by its implementation in Java. To configure the Java library as dependency to the VDB, see <a href="/author/display/TEIID/Support+for+User-Defined+Functions+%28Non-Pushdown%29#SupportforUser-DefinedFunctions%28Non-Pushdown%29-MetadataDynamicVDBs">Support for User-Defined Functions</a></td></tr></table></div>

<p><b>PROCEDURE OPTIONS</b>:(the below are well known options, any others properties defined will be considered as extension metadata)</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Data Type or Allowed Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> UUID </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> Unique Identifier </td>
</tr>
<tr>
<td class='confluenceTd'> NAMEINSOURCE </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> In the case of source </td>
</tr>
<tr>
<td class='confluenceTd'> ANNOTATION </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> Description of the procedure </td>
</tr>
<tr>
<td class='confluenceTd'> UPDATECOUNT </td>
<td class='confluenceTd'> int </td>
<td class='confluenceTd'> if this procedure updates the underlying sources, what is the update count, when update count is &gt;1 the XA protocol for execution is enforced </td>
</tr>
</tbody></table>
</div>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example:Define Procedure</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CREATE VIRTUAL PROCEDURE CustomerActivity(customerid integer) RETURNS (name varchar(25), activitydate date, amount decimal) AS
   BEGIN
   ...
   END
</pre>
</div></div>

<p><b>Relational Extension OPTIONS</b>:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Data Type or Allowed Values </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> native-query </td>
<td class='confluenceTd'> Parameterized String </td>
<td class='confluenceTd'> Applies to both functions and procedures. The replacement for the function syntax rather than the standard prefix form with parens.  See also <a href="/author/display/TEIID/Translators#Translators-native">Translators#native</a></td>
</tr>
<tr>
<td class='confluenceTd'> non-prepared </td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> Applies to JDBC procedures using the native-query option. If true a PreparedStatement will not be used to execute the native query.</td>
</tr>
</tbody></table>
</div>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example:Native Query</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">CREATE FOREIGN FUNCTION func (x integer, y integer) returns integer OPTIONS ("teiid_rel:native-query" '$1 &lt;&lt; $2');</pre>
</div></div>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example:Sequence Native Query</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">CREATE FOREIGN FUNCTION seq_nextval () returns integer OPTIONS ("teiid_rel:native-query" 'seq.nextval');</pre>
</div></div>
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Until Teiid provides higher-level metadata support for sequences, a source function representation is the best fit to expose sequence functionality.</td></tr></table></div>

<h2><a name="DDLMetadata-Options"></a>Options</h2>

<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_options.jpg?version=1&amp;modificationDate=1344460097000" style="border: 1px solid black" /></span></p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Any option name of the form prefix:key will attempt to be resolved against the current set of namespaces.  Failure to resolve will result in the option name being left as is.  A resolved name will be replaced with {uri}key.  See also Namespaces for Extension Metadata.</td></tr></table></div>

<p>Options can also be added using the ALTER statement. See ALTER stmt.</p>

<h2><a name="DDLMetadata-ALTERStatement"></a>ALTER Statement</h2>

<p>ALTER statements currently primarily supports adding OPTIONS properties to Tables, Views and Procedures. Using a ALTER statement, you can either add, modify or remove a property.</p>

<p><span class="image-wrap" style=""><img src="/author/download/attachments/20316193/alter.png?version=1&amp;modificationDate=1360885624000" style="border: 1px solid black" /></span></p>

<h3><a name="DDLMetadata-ALTERCOLUMN"></a>ALTER COLUMN</h3>
<p><span class="image-wrap" style=""><img src="/author/download/attachments/20316193/alterColumn.png?version=1&amp;modificationDate=1360885631000" style="border: 1px solid black" /></span></p>

<h3><a name="DDLMetadata-ALTEROPTION"></a>ALTER OPTION</h3>
<p><span class="image-wrap" style=""><img src="/author/download/attachments/20316193/alterOption.png?version=1&amp;modificationDate=1360885636000" style="border: 1px solid black" /></span></p>


<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example ALTER</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
ALTER FOREIGN TABLE "customer" OPTIONS (ADD CARDINALITY 10000);
ALTER FOREIGN TABLE "customer" ALTER COLUMN "name" OPTIONS(SET UPDATABLE FALSE)
</pre>
</div></div>

<p>ALTER statements are especially useful, when user would like to modify/enhance the metadata that has been imported from a NATIVE datasource. For example, if you have a database called "northwind", and you imported that metadata and would like to add CARDINALITY to its "customer" table, you can use ALTER statement, along with "chainable" metadata repositories feature to add this property to the desired table. The below shows an example -vdb.xml file, that illustrates the usage.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example VDB</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;vdb name="northwind" version="1"&gt;
    &lt;model name="nw"&gt;
        &lt;property name="importer.importKeys" value="true"/&gt;
        &lt;property name="importer.importProcedures" value="true"/&gt;
         &lt;source name="northwind-connector" translator-name="mysql" connection-jndi-name="java:/nw-ds"/&gt;
         &lt;metadata type = "NATIVE,DDL"&gt;&lt;![CDATA[
              ALTER FOREIGN TABLE "customer" OPTIONS (ADD CARDINALITY 10000);
              ALTER FOREIGN TABLE "customer" ALTER COLUMN "name" OPTIONS(SET UPDATABLE FALSE);
         ]]&gt;
         &lt;/metadata&gt;
    &lt;/model&gt;
&lt;/vdb&gt;
</pre>
</div></div>

<h2><a name="DDLMetadata-DataTypes"></a>Data Types</h2>

<p>The following are the supported data types in the Teiid.</p>

<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/datatypes.png?version=2&amp;modificationDate=1344543071000" style="border: 1px solid black" /></span></p>

<h2><a name="DDLMetadata-NamespacesforExtensionMetadata"></a>Namespaces for Extension Metadata</h2>

<p>When defining the extension metadata in the case of Custom Translators, the properties on tables/views/procedures/columns can define namespace for the properties such that they will not collide with the Teiid specific properties. The property should be prefixed with alias of the Namespace.  Prefixes starting with teiid&#95; are reserved for use by Teiid.</p>

<p><span class="image-wrap" style="display: block; text-align: center"><img src="/author/download/attachments/20316193/create_namespace.jpg?version=2&amp;modificationDate=1344460089000" style="border: 1px solid black" /></span></p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Example of Namespace</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SET NAMESPACE 'http://custom.uri' AS foo

CREATE VIEW MyView (...) OPTIONS ("foo:mycustom-prop" 'anyvalue')
</pre>
</div></div>

<h3><a name="DDLMetadata-BuiltinNamespacePrefixes"></a>Built-in Namespace Prefixes</h3>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Prefix </th>
<th class='confluenceTh'> URI </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> teiid_rel </td>
<td class='confluenceTd'> <a href="http://www.teiid.org/ext/relational/2012" class="external-link" rel="nofollow">http://www.teiid.org/ext/relational/2012</a> </td>
<td class='confluenceTd'> Relational extensions.  Uses include function and native query metadata </td>
</tr>
<tr>
<td class='confluenceTd'> teiid_sf </td>
<td class='confluenceTd'> <a href="http://www.teiid.org/translator/salesforce/2012" class="external-link" rel="nofollow">http://www.teiid.org/translator/salesforce/2012</a> </td>
<td class='confluenceTd'> Salesforce extensions. </td>
</tr>
</tbody></table>
</div>


<h1><a name="DDLMetadata-FullExampleshowingaboveDDLbasedmetadata"></a>Full Example showing above DDL based metadata</h1>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Full Example VDB with View Definition</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;vdb name="twitter" version="1"&gt;

    &lt;description&gt;Shows how to call Web Services&lt;/description&gt;

    &lt;property name="UseConnectorMetadata" value="cached" /&gt;

    &lt;model name="twitter"&gt;
        &lt;source name="twitter" translator-name="rest" connection-jndi-name="java:/twitterDS"/&gt;
    &lt;/model&gt;
    &lt;model name="twitterview" type="VIRTUAL"&gt;
         &lt;metadata type="DDL"&gt;&lt;![CDATA[
             CREATE VIRTUAL PROCEDURE getTweets(query varchar) RETURNS (created_on varchar(25), from_user varchar(25), to_user varchar(25),
                 profile_image_url varchar(25), source varchar(25), text varchar(140)) AS
                select tweet.* from
                        (call twitter.invokeHTTP(action =&gt; 'GET', endpoint =&gt;querystring('',query as "q"))) w,
                        XMLTABLE('results' passing JSONTOXML('myxml', w.result) columns
                        created_on string PATH 'created_at',
                        from_user string PATH 'from_user',
                        to_user string PATH 'to_user',
                        profile_image_url string PATH 'profile_image_url',
                        source string PATH 'source',
                        text string PATH 'text') tweet;
                CREATE VIEW Tweet AS select * FROM twitterview.getTweets;
        ]]&gt; &lt;/metadata&gt;
    &lt;/model&gt;

    &lt;translator name="rest" type="ws"&gt;
                &lt;property name="DefaultBinding" value="HTTP"/&gt;
                &lt;property name="DefaultServiceMode" value="MESSAGE"/&gt;
    &lt;/translator&gt;
&lt;/vdb&gt;
</pre>
</div></div>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/DDL+Metadata">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=20316193&revisedVersion=34&originalVersion=33">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/DDL+Metadata?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>