Thursday, 10 July 2014

Real time issue in Teradata

This error will happen when you update the target with multiple rows from the source.
If you defined primary index field for your target and if you defined those fileds in update query condition, this error will be obvious one.

For example,

  1. UPDATE tbl_emp
  2. FROM
  3. (SELECT
  4. id,
  5. name
  6. FROM tbl_dept) DEPT
  7. SET name = DEPT.name
  8. WHERE
  9. tbl_emp.id = DEPT.id;


In the above code, if tbl_dept has non-unique values and tbl_emp is a set table, then the error will appear.
Solution:
You can render the query with DISTINCT in the select query.

  1. UPDATE tbl_emp
  2. FROM
  3. (SELECT DISTNCT
  4. id,
  5. name
  6. FROM tbl_dept) DEPT
  7. SET name = DEPT.name
  8. WHERE
  9. tbl_emp.id = DEPT.id;

No comments:

Post a Comment