Logical Tables » Creating logical tables » Defining the primary key for a table

Defining the primary key for a table

MicroStrategy requires each table to have a primary key, which is a unique value identifying each distinct data record or row. A primary key can be defined by one or more columns in the table. For more information on primary keys, see Uniquely identifying data in tables with key structures.

MicroStrategy determines the primary key for a table based on the attributes mapped to the columns of the table. In the Table Editor on the Layout tab, a key icon displayed by the attribute name indicates that the attribute is part of the primary key for this table. The primary key is made up of the lowest level attributes. For example, a warehouse table's primary key is defined using the columns CUSTOMER_ID, PRODUCT_ID, and ORDER_ID. If these three columns are mapped to attributes in MicroStrategy, then the primary key is represented correctly. In this case, from the Table Editor’s Layout tab, you can select the The key specified is the true key for the warehouse table check box. This is the default behavior for all tables added to a MicroStrategy project.

If the primary key for the warehouse table is not identical to the attributes listed as key attributes for the table in MicroStrategy, clear the The key specified is the true key for the warehouse table check box. Using the example described above, consider the scenario in which CUSTOMER_ID and PRODUCT_ID are mapped to MicroStrategy attributes, but ORDER_ID is not mapped to an attribute in MicroStrategy. In this case, only CUSTOMER_ID and PRODUCT_ID would be recognized by MicroStrategy as part of the table’s primary key. In this scenario, this check box should be cleared so that the warehouse table’s primary key can be verified. Otherwise, selecting this check box for such a scenario could cause incorrect or erroneous data to be returned.