Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.1 » UltraLite - Database Management and Reference » UltraLite as a MobiLink client » UltraLite clients » Primary key uniqueness in UltraLite


Determine the most recently assigned GLOBAL AUTOINCREMENT value

You can retrieve the GLOBAL AUTOINCREMENT value that was chosen during the most recent insert operation. Since these values are often used for primary keys, knowing the generated value may let you more easily insert rows that reference the primary key of the first row. You can check the value with:

  • UltraLite for C/C++   Use the GetLastIdentity function on the ULConnection object.

  • UltraLite.NET   Use the LastIdentity property on the ULConnection class.

  • UltraLite for M-Business Anywhere   Use the GetLastIdentity method on the Connection class.

  • API UltraLiteJ   Use the getLastIdentity method on the Connection interface.

The returned value is an unsigned 64-bit integer, database data type UNSIGNED BIGINT. Since this statement only allows you to determine the most recently assigned default value, you should retrieve this value soon after executing the insert statement to avoid spurious results.


Occasionally, a single INSERT statement may include more than one column of type GLOBAL AUTOINCREMENT. In this case, the return value is one of the generated default values, but there is no reliable means to determine which one. For this reason, you should design your database and write your INSERT statements in a way that avoids this situation.

 See also