Wednesday, November 20, 2013

Update matching rows in one table with data from another table

Update matching rows in t1 with data from t2

update t1
set (c1, c2, c3) =
(select c1, c2, c3 from t2
 where t2.user_id = t1.user_id)
where exists
(select * from t2
 where t2.user_id = t1.user_id)

The "where exists" part it to prevent updating the t1 columns to null where no match exists.

Tuesday, November 12, 2013

Getting rid of invalid Tablespace references

Suppose you import a big project to a DB, and notice that a number of tables in the Project refer to invalid (non- existing) tablespaces.

One way of updating this would be from AppDesigner.
Open Table. Select Tools-> Data Administration-> Set Tablespace, and set the correct Tablespace

But in case you have a large number of records having this problem, and don't want to go through the pain of updating it one by one, here's a backend update that will help.
UPDATE PSRECTBLSPC set DDLSPACENAME='PTAPP', DBNAME='PSPTDMO' where DDLSPACENAME in (<INVALID TABLESPACE>)