Forum Discussion

Ahmad Saleh's avatar
Ahmad Saleh
Copper Contributor
May 22, 2018
Solved

After insert trigger on a table that has a Primary Key

Hi All I have the following 2 tables: Order with the following columns: OrderID as PK, Order Name, etc. Delivery with the following columns: DeliveryID as PK, OrderID, date, etc. I wrote af...
  • frederic MICHALAK's avatar
    May 23, 2018

    Hi Ahmad, 

    I'm not sure to fully understand your need, but please consider the following bullet :

    - From performance perspective, triggers are not the best way to go.

    - Why don't you allow your Order record to be childless, and then add a record into the Delivery table after, via user interface typically ? 

     

    Finally, to keep your solution in place : 

    - Define your DeliveryID column as a BigInt, and enable the Identity property to True (ref your screenshot). Then the value of your DeliveryID column will be automatically incremented for each new record.

    - Define your DeliveryID column as a UniqueIdentifier, and define a default value as new_sequentialid().

     

    Hope this helps.

    Fred.M.

Resources