There's more...

We not only have other alternatives to the update statement, but we can also write an update as an UPSERT, meaning, it executes an INSERT if not and performs the UPDATE if the row exists:

MERGE INTOTable1 AS t1USINGTable1_this AS t2ONt1.PK_Col=t2.PK_ColWHEN MATCHED THEN UPDATESETCol1=t1.Col1,Col2=t1.Col2WHEN NOT MATCHED THENINSERT(t1.PK_Col,t1.Col1,t1.Col2);

You can update the data in a table not only using the update statement but using three other alternatives:

  • MERGE INTO: Merges a source row set into a target table based on whether any target rows satisfy a specified matching condition with the source row. The MERGE statement combines the INSERT and UPDATE statements into a single conditional statement. What makes MERGE ...

Get Teradata Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.