Export (0) Print
Expand All

Creating Primary and Unique Keys in XML Schemas

Visual Studio .NET 2003

A primary key defines a column in a table as unique and required (null values are not allowed), whereas a unique key defines a column in a table as unique and optional (null values are allowed).

You designate columns in tables as keys, which allow you to create relationships and constraints. For more information about keys, see Tables, Columns, Keys, and Constraints in XML Schemas.

The following is a visual representation of a Key definition in the XML Designer


To create a primary or unique key in an XML Schema or dataset

  1. Right-click to the left of the row of the element you want to designate as a key. Approximately where the key glyph is in the picture above.
  2. Click Add then click New Key.

    The Edit Key dialog box appears.

  3. In the Name box, replace the default name with a name appropriate for this key.

    The Selector box and the Field area will default to the element you chose in Step 1.

  4. If you need a key that is comprised of more than one column definition (a multipart key), select additional elements in the Field area.
  5. If you need to allow the element to contain a null value, select nullable.
  6. If you need a primary key, select Primary Key. Otherwise, a unique key will be created.

Next Steps

See Also

Relational Data in XML Schemas | Tables, Columns, Keys, and Constraints in XML Schemas | Nested Relationships in XML | Creating Tables in XML Schemas | Creating One-to-Many Relationships in XML Schemas and Datasets | Creating Nested Relationships in XML Schemas | XML Schemas and Data | XML Schemas and the XML Designer | Creating XML Schemas and Datasets | XML Files

© 2014 Microsoft