Skip to main content

 

ThoughtSpot

Change the Primary Key for a Table

Overview

Explains what the feature is or what its benefits are to the user or customer.

Feature

Use this procedure to change the primary key for a table. But use it with caution, particularly if you are changing to a primary key for which values are not unique.

You can change the primary key of a table without having to TRUNCATE it first and reload the data. However, changing the primary key could result in data deletion. This is because of the upsert behavior which is applied when multiple rows have the same primary key. This is very important to understand ahead of time, if you are considering changing to a primary key for which values are not unique.

To change the primary key, first remove any existing primary key, and then define a new one (if any). You do not need to truncate the tables to do this operation beginning in version 3.2. Any dependent objects (answers, pinboards, or worksheets) will remain intact.

To change the primary key of a table:

  1. Connect to the Database with the ThoughtSpot SQL Command Line (TQL).
  2. Drop the existing primary key (if any), by issuing a command like this example:
    TQL> ALTER TABLE "cart"
         DROP CONSTRAINT 
         PRIMARY KEY;
  3. Add a new primary key, if desired:
    TQL> ALTER TABLE "cart"
         ADD CONSTRAINT 
         PRIMARY KEY ("owner_id");
  • Was this article helpful?