KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Preparing for 4D v14 Journaling Code Samples
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: March 6, 2014
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

These code examples are from the "Preparing for 4D v14 Journaling" Webinar.

To set an existing field to be a Primary Key:

Begin SQL
   ALTER TABLE Table_1 ADD PRIMARY KEY( myUUID);
End SQL


To create a brand new Primary Key:

Begin SQL
    ALTER TABLE Table_1 ADD TRAILING myUUID UUID AUTO_GENERATE PRIMARY KEY;
End SQL


An example of adding a new Primary Key named "myUUID" to every table in the database:

C_TEXT($sql_t;$tableName_t)
C_LONGINT($curTable_l;$numTables_l)

$numTables_l:=Get last table number

For ($curTable_l;1;$numTables_l)
   $sql_t:=""
   If (Is table number valid($curTable_l))

      $tableName_t:=Table name($curTable_l)
      $sql_t:=$sql_t+"ALTER TABLE ["+$tableName_t+"] "
      $sql_t:=$sql_t+"ADD TRAILING myUUID UUID AUTO_GENERATE PRIMARY KEY;"

      Begin SQL
         EXECUTE IMMEDIATE :$sql_t;
      End SQL

   End if
End for