Creating a New Class Key

This section describes how to create a key as the unique identifier for a class. The class must exist prior to creating the key.

Ee796350.note(en-US,CS.20).gifNote

Keys can be single or multi-membered. Keys must be unique across a catalog.

You can create a single-valued key in two ways:

  • Implicitly create the key by setting the value corresponding to the key equal to True (1) for both the GenerateKeyDef attribute in the Class Definition table and the IsPrimaryKey attribute in the Member Definition table. Explicitly creating a new instance in the Class Key Definition table is then unnecessary.

  • Explicitly create the key in a two-step process. The first step is to insert a new instance of a Class Key Definition (clskeydef), populating the attributes, and saving the changes. For information about the Class Key Definition, see Key Definition Meta-data.

    The second step is to define the member of the key through the Class Key Member (keymem) table. For information about this step, see Creating a New Class Key Member.

For multi-membered keys, you can only define the member of the key through the Class Key Member (keymem).

We continue our example (which originated in Creating a New Class) by creating the (multi-membered) key for the OrderFormHeader class.

The following table lists the attributes and values of the Class Key Definition table for the OrderFormHeader class. Unspecified optional attributes are not shown. In the R/O column, R = required, O = optional.

Required attribute name Attribute value Type R/O Purpose
ClassKeyDefName "myOrderFormHeaderKey" String R Uniquely identifies the class key. Must be unique across the catalog.
ClassDefName "OrderFormHeader" String R The name of the class for the key.
Description "Unique key for the OrderFormHeader Class." String O Describes the key.

Running Example - Step 4

Create a new key for the OrderFormHeader class.

Ee796350.note(en-US,CS.20).gifNote

  • The code provided in this example is for demonstration purposes only. The OrderFormHeader class created in this example already exists in the Data Warehouse schema. The CreateSchemaObject.vbs file included in the Commerce Server 2002 Software Development Kit should be used to automate the process of extending the schema. For more information about the script, see Create Schema Object Script.
'Create an instance in the Class Key Definition table.
   recNew.Open "Key/myOrderFormHeaderKey", cnnConnection, _
    adModeWrite, adCreateOverwrite

'Set the attributes.
   recNew("ClassDefName") = "OrderFormHeader"
   recNew("Description") = "Unique key for the OrderFormHeader class."

'Save the new row.
   recNew("__Commit") = 1
   recNew.Fields.Update
   recNew.Close

The next step is to define the members of this key.

See Also

Creating a New Class Key Member

Create Schema Object Script

Copyright © 2005 Microsoft Corporation.
All rights reserved.