Search code examples
sqlteradatateradata-sql-assistant

how do I create a delta query in Teradata SQL


I am using Teradata and my query is

SELECT deptno, name, salary
FROM personnel.employee;

Above table automatically gets updated everyday e.g. new rows added/deleted, existing values gets updated. There are no date/time field.

Is there a way I can only get the changes and not all the records? Also is there a way to know which of the record are new vs. which are updated? Happy to run multiple query as the file size will be small. Does Teradata have internal table where it keeps record of updates/deletes? do I need special permission to access such table? thanks.


Solution

  • In the given scenario itself you don'T have a chance to see the diff. But some ideas to improve the table / situation:

    • You can change the Table to a TEMPORAL table. Then Teradata will add invisible columns with timestamps that are maintained automatically. With this you can access these temporal columns to get the diff. In your case it looks like a transactional temporal table. (This is what I would prefer)
    • You can create you own table holding the latest status and each join with this table to get the delta.