You can ensure that primary keys are unique by using the newid( ) function to create universally unique values for your primary key. The resulting UUIDs can be converted to a string using the uuidtostr( ) function, and converted back to binary using the strtouuid( ) function.
UUIDs, also known as GUIDs, are unique across all computers. However, the values are completely random and so cannot be used to determine when a value was added, or the order of values. UUID values are also considerably larger than the values required by other methods (including global autoincrement), and require more table space in both the primary and foreign key tables. Indexes on tables using UUIDs are also less efficient.
SQL Anywhere databases:
The following SQL Anywhere CREATE TABLE statement creates a primary key that is universally unique:
CREATE TABLE customer ( cust_key UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID( ), rep_key VARCHAR(5), PRIMARY KEY(cust_key))
|Discuss this page in DocCommentXchange.
Send feedback about this page using email.
|Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1|