Is there an equivalent to the iSeries OVRDBF command in SQL?

3k Views Asked by At

I have a requirement in a SQL environment that under specific circumstances, all references to table (or view) A in a procedure actually use table (or view) B. On the iSeries I would have used the OVRDBF command to override references to table A with table B: OVRDBF FILE(A) TOFILE(B). What would be the equivalent to this in SQL? Is there one?

My goal is to end up with a procedure that is ignorant of the override. I don't want conditional logic inside the procedure that directs processing at table B when certain conditions are met. The vision:

Under typical circumstances: Just invoke the procedure

Under specific alternative circumstances: Perform the OVRDBF equivalent and then Invoke the procedure

2

There are 2 best solutions below

2
On

As Ed mentions if you can modify your procedure:

1) Create an alias for file(A)

CREATE ALIAS XYZ FOR A

2) Modify the procedure to reference XYZ instead of A.

3) When running the procedure to use file B execute

DROP ALIAS XYZ;
CREATE ALIAS XYZ FOR B;
CALL PROCEDURE;
DROP ALIAS XYZ;
CREATE ALIAS XYZ FOR A;

If you can't modify the procedure and you're not worried about simultaneous access to table A you could use:

RENAME TABLE A TO C;
CREATE ALIAS A FOR B;
CALL PROCEDURE;
DROP ALIAS A;
RENAME TABLE C TO A;
1
On

Not sure which SQL environment support which options:

I believe DB2 has a CREATE ALIAS statement. Write the SQL over the alias.

Another possibility: run your queries over views: where you would do the OVRDBF, drop the view and rebuild it over the desired table.