方案版本範例 examples-of-schemas-edition
擴充表格 extending-a-table
若要擴充 nms:recipient 結構描述收件者表格,請套用下列程式:
-
使用下列資料建立擴充功能結構描述(cus:extension):
code language-none <srcSchema mappingType="sql" name="extension" namespace="cus" xtkschema="xtk:srcSchema" extendedSchema="nms:recipient"> <enumeration basetype="string" default="area1" name="area"> <value label="Zone 1" name="area1"/> <value label="Zone 2" name="area2"/> </enumeration> <element name="extension"> <dbindex name="area"> <keyfield xpath="location/@area"/> </dbindex> <attribute label="Loyalty code" name="fidelity" type="long"/> <element name="location"> <attribute name="area" label="Purchasing zone" type="string" length="50" enum="area"/> </element> </element> </srcSchema>
在此範例中,已新增索引欄位(fidelity),且 位置 元素(已存在於 nms:recipient 結構描述中)已加入列舉欄位(area)。
note important IMPORTANT 請記得新增 extendedSchema 屬性以參考擴充功能結構描述。 -
檢查擴充結構描述是否為 nms:recipient 結構描述,以及是否存在其他資料:
code language-none <schema dependingSchemas="cus:extension" mappingType="sql" name="recipient" namespace="nms" xtkschema="xtk:schema"> ... <enumeration basetype="string" default="area1" name="area"> <value label="Zone 1" name="area1"/> <value label="Zone 2" name="area2"/> </enumeration> ... <element autopk="true" name="recipient" sqltable="NmsRecipient"> <dbindex name="area"> <keyfield xpath="location/@area"/> </dbindex> ... <attribute belongsTo="cus:extension" label="Loyalty code" name="fidelity" sqlname="iFidelity" type="long"/> <element name="location"> ... <attribute enum="area" label="Purchasing zone" length="50" name="area" sqlname="sArea" type="string"/> </element> ... </element> </schema>
從資料庫更新輔助程式產生的SQL指令碼如下:
code language-none ALTER TABLE NmsRecipient ADD iFidelity INTEGER; UPDATE NmsRecipient SET iFidelity = 0; ALTER TABLE NmsRecipient ALTER COLUMN iFidelity SET NOT NULL;ALTER TABLE NmsRecipient ALTER COLUMN iFidelity SET Default 0; ALTER TABLE NmsRecipient ADD sArea VARCHAR(50); CREATE INDEX NmsRecipient_area ON NmsRecipient(sArea);
連結的集合表格 linked-collection-table
本節說明如何建立連結至具有基數1-N之收件者表格的訂單表格。
排序表格來源結構描述:
<srcSchema label="Order" name="order" namespace="cus" xtkschema="xtk:srcSchema">
<element autopk="true" name="order">
<compute-string expr="@number" + '(' + ToString(@date) + ')'/>
<attribute label="Number" length="128" name="number" type="string"/>
<attribute desc="Order date" label="Date" name="date" type="datetime" default="GetDate()"/>
<attribute desc="order total" label="Total" name="total" type="double"/>
<element label="Recipient" name="recipient" revDesc="Orders associated with this recipient" revIntegrity="own" revLabel="Orders" target="nms:recipient" type="link"/>
</element>
</srcSchema>
資料表型別是 autopk,以建立自動產生的主索引鍵,供連結至收件者資料表的連結使用。
產生的結構描述:
<schema label="Order" mappingType="sql" name="order" namespace="cus" xtkschema="xtk:schema">
<element autopk="true" label="Order" name="order" sqltable="CusOrder">
<compute-string expr="ToString(@date) + ' - ' + @number"/>
<dbindex name="id" unique="true">
<keyfield xpath="@id"/>
</dbindex>
<key internal="true" name="id">
<keyfield xpath="@id"/>
</key>
<dbindex name="recipientId">
<keyfield xpath="@recipient-id"/>
</dbindex>
<attribute desc="Internal primary key" label="Primary key" name="id" sqlname="iOrderId" type="long"/>
<attribute label="Number" length="128" name="number" sqlname="sNumber" type="string"/>
<attribute desc="Order date" label="Date" name="date" sqlname="tsDate" type="datetime"/>
<attribute desc="order total" label="Total" name="total" sqlname="Total" type="double"/>
<element label="Recipient" name="recipient" revLink="order" target="nms:recipient" type="link">
<join xpath-dst="@id" xpath-src="@recipient-id"/>
</element>
<attribute advanced="true" label="Foreign key of 'Recipient' link ('id' field)" name="recipient-id" sqlname="iRecipientId" type="long"/>
</element>
</schema>
表格建立SQL命令檔如下:
CREATE TABLE CusOrder(dTotal DOUBLE PRECISION NOT NULL Default 0, iOrderId INTEGER NOT NULL Default 0, iRecipientId INTEGER NOT NULL Default 0, sNumber VARCHAR(128), tsDate TIMESTAMP Default NULL);
CREATE UNIQUE INDEX CusOrder_id ON CusOrder(iOrderId);
CREATE INDEX CusOrder_recipientId ON CusOrder(iRecipientId);
INSERT INTO CusOrder (iOrderId) VALUES (0);
擴充功能表格 extension-table
擴充表格可讓您擴充連結基數1-1之連結表格中現有表格的內容。
擴充功能表格的用途是避免表格中支援的欄位數限制,或最佳化資料佔用的空間(依需求使用)。
正在建立擴充功能資料表結構描述(cus:feature):
<srcSchema mappingType="sql" name="feature" namespace="cus" xtkschema="xtk:srcSchema">
<element autopk="true" name="feature">
<attribute label="Children" name="children" type="byte"/>
<attribute label="Single" name="single" type="boolean"/>
<attribute label="Spouse first name" length="100" name="spouseFirstName" type="string"/>
</element>
</srcSchema>
在收件者表格上建立擴充功能綱要,以新增基數1-1的連結:
<srcSchema extendedSchema="nms:recipient" label="Recipient" mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:srcSchema">
<element name="recipient">
<element desc="Features" integrity="own" label="Features" name="feature" revCardinality="single" revLink="recipient" target="cus:feature" type="link"/>
</element>
</srcSchema>
建立擴充功能表格的SQL指令碼如下:
CREATE TABLE CusFeature( iChildren NUMERIC(3) NOT NULL Default 0, iFeatureId INTEGER NOT NULL Default 0, iSingle NUMERIC(3) NOT NULL Default 0, sSpouseFirstName VARCHAR(100));
CREATE UNIQUE INDEX CusFeature_id ON CusFeature(iFeatureId);
INSERT INTO CusFeature (iFeatureId) VALUES (0);
收件者表格SQL更新指令碼如下:
ALTER TABLE NmsRecipient ADD iFeatureId INTEGER;
UPDATE NmsRecipient SET iFeatureId = 0;
ALTER TABLE NmsRecipient ALTER COLUMN iFeatureId SET NOT NULL;
ALTER TABLE NmsRecipient ALTER COLUMN iFeatureId SET Default 0;
CREATE INDEX NmsRecipient_featureId ON NmsRecipient(iFeatureId);
溢位表格 overflow-table
溢位表格是擴充表格(基數1-1),但要擴充之表格的連結宣告會填入溢位表格的綱要。
溢位表格包含要擴充之表格的外部索引鍵。 因此,不會修改要擴充的表格。 兩個表格之間的關係是要擴充之表格的主鍵值。
正在建立溢位資料表結構描述(cus:overflow):
<srcSchema label="Overflow" name="overflow" namespace="cus" xtkschema="xtk:srcSchema">
<element name="overflow">
<key internal="true" name="id">
<keyfield xlink="recipient"/>
</key>
<attribute label="Children" name="children" type="byte"/>
<attribute label="Single" name="single" type="boolean"/>
<attribute label="Spouse first name" length="100" name="spouseFirstName" type="string"/>
<element label="Customer" name="recipient" revCardinality="single" revIntegrity="own" revExternalJoin="true" target="nms:recipient" type="link"/>
</element>
</srcSchema>
表格建立SQL命令檔如下:
CREATE TABLE CusOverflow(iChildren NUMERIC(3) NOT NULL Default 0, iRecipientId INTEGER NOT NULL Default 0, iSingle NUMERIC(3) NOT NULL Default 0, sSpouseFirstName VARCHAR(100));
CREATE UNIQUE INDEX CusOverflow2_id ON CusOverflow2(iRecipientId);
關係表 relationship-table
關係表格可讓您連結兩個具有基數N-N的表格。此表格僅包含要連結之表格的外部索引鍵。
群組(nms:group)與收件者(nms:recipient)之間的關係表範例。
關係表的Source結構描述:
<srcSchema name="rcpGrpRel" namespace="cus">
<element name="rcpGrpRel">
<key internal="true" name="id">
<keyfield xlink="rcpGroup"/>
<keyfield xlink="recipient"/>
</key>
<element integrity="neutral" label="Recipient" name="recipient" revDesc="Groups to which this recipient belongs" revIntegrity="own" revLabel="Groups" target="nms:recipient" type="link"/>
<element integrity="neutral" label="Group" name="rcpGroup" revDesc="Recipients in the group" revIntegrity="own" revLabel="Recipients" revLink="rcpGrpRel" target="nms:group" type="link"/>
</element>
</srcSchema>
產生的結構描述如下:
<schema mappingType="sql" name="rcpGrpRel" namespace="cus" xtkschema="xtk:schema">
<element name="rcpGrpRel" sqltable="CusRcpGrpRel">
<compute-string expr="ToString([@rcpGroup-id]) + ',' + ToString([@recipient-id])"/>
<dbindex name="id" unique="true">
<keyfield xpath="@rcpGroup-id"/>
<keyfield xpath="@recipient-id"/>
</dbindex>
<key internal="true" name="id">
<keyfield xpath="@rcpGroup-id"/>
<keyfield xpath="@recipient-id"/>
</key>
<dbindex name="rcpGroupId">
<keyfield xpath="@rcpGroup-id"/>
</dbindex>
<dbindex name="recipientId">
<keyfield xpath="@recipient-id"/>
</dbindex>
<element integrity="neutral" label="Recipient" name="recipient" revLink="rcpGrpRel" target="nms:recipient" type="link">
<join xpath-dst="@id" xpath-src="@recipient-id"/>
</element>
<attribute advanced="true" label="Foreign key of 'Recipient' link ('id' field)" name="recipient-id" sqlname="iRecipientId" type="long"/>
<element integrity="neutral" label="Group" name="rcpGroup" revLink="rcpGrpRel" target="nms:group" type="link">
<join xpath-dst="@id" xpath-src="@rcpGroup-id"/>
</element>
<attribute advanced="true" label="Foreign key of 'Group' link ('id' field)" name="rcpGroup-id" sqlname="iRcpGroupId" type="long"/>
</element>
</schema>
表格建立SQL命令檔如下:
CREATE TABLE CusRcpGrpRel( iRcpGroupId INTEGER NOT NULL Default 0, iRecipientId INTEGER NOT NULL Default 0);
CREATE UNIQUE INDEX CusRcpGrpRel_id ON CusRcpGrpRel(iRcpGroupId, iRecipientId);
CREATE INDEX CusRcpGrpRel_recipientId ON CusRcpGrpRel(iRecipientId);
使用案例:將欄位連結至現有的參考表格 uc-link
此使用案例示範如何使用現有的參考表格作為內建Adobe Campaign列舉機制(enum、userEnum或dbEnum)的替代方案。
您也可以使用現有的參考表格作為結構描述中的分項清單。 若要達成此目的,請在資料表和參考資料表之間建立連結,並新增屬性 displayAsField="true"。
在此範例中,參考表格包含銀行名稱與識別碼的清單:
<srcSchema entitySchema="xtk:srcSchema" img="cus:bank16x16.png" label="Bank" mappingType="sql" name="bank" namespace="cus"
xtkschema="xtk:srcSchema">
<element img="cus:bank16x16.png" label="Banks" name="bank">
<compute-string expr="@name"/>
<key name="id">
<keyfield xpath="@id"/>
</key>
<attribute label="Bank Id" name="id" type="short"/>
<attribute label="Name" length="64" name="name" type="string"/>
</element>
</srcSchema>
在使用此參考資料表的任何資料表中,定義連結並新增 displayAsField="true" 屬性。
<element displayAsField="true" label="Bank" name="bank" target="cus:bank" type="link" noDbIndex="true"/>
使用者介面不會顯示連結,但會顯示欄位。 當使用者選取該欄位時,他們可以從參照表中選取值或使用自動完成功能。
-
為了使其自動完成,您必須在參考表中定義計算字串。
-
在連結定義中新增 noDbIndex="true" 屬性,以防止Adobe Campaign在連結來源資料表中儲存的值上建立索引。