MsiDatabaseGetPrimaryKeysA function (msiquery.h)

The MsiDatabaseGetPrimaryKeys function returns a record containing the names of all the primary key columns for a specified table. This function returns a handle that should be closed using MsiCloseHandle.


UINT MsiDatabaseGetPrimaryKeysA(
  [in]  MSIHANDLE hDatabase,
  [in]  LPCSTR    szTableName,
  [out] MSIHANDLE *phRecord


[in] hDatabase

Handle to the database. See Obtaining a Database Handle.

[in] szTableName

Specifies the name of the table from which to obtain primary key names.

[out] phRecord

Pointer to the handle of the record that holds the primary key names.

Return value

This function returns UINT.


The field count of the returned record is the count of primary key columns returned by the MsiDatabaseGetPrimaryKeys function. The returned record contains the table name in Field (0) and the column names that make up the primary key names in succeeding fields. These primary key names correspond to the column numbers for the fields.

This function cannot be used with the _Tables table or the _Columns table.

Note that it is recommended to use variables of type PMSIHANDLE because the installer closes PMSIHANDLE objects as they go out of scope, whereas you must close MSIHANDLE objects by calling MsiCloseHandle. For more information see Use PMSIHANDLE instead of HANDLE section in the Windows Installer Best Practices.


The msiquery.h header defines MsiDatabaseGetPrimaryKeys as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.


Minimum supported client Windows Installer 5.0 on Windows Server 2012, Windows 8, Windows Server 2008 R2 or Windows 7. Windows Installer 4.0 or Windows Installer 4.5 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003 or Windows XP
Target Platform Windows
Header msiquery.h
Library Msi.lib
DLL Msi.dll

See also

General Database Access Functions