Some time problems are not that easy to resolve because we got stuck in our think box. But how can we think out of box if we sit in a cube( jokes apart).
Today we are faced an issue where we have to rename table name and add new column in it so that we can differentiate existing data with new added records. But it wasn't possible because this table is used as first table in joins.
for example :
tblX
id name description
tblB
Bid Xid Values
select * from tblX a
inner join tblB b on a.id=b.Aid
and i am doing this kind of thing hundred of places in my SPs.
Now my requirement is something like that
Rename table to tblX to tblXYZ and add new column CategoryType.
Update all records with CategoryType 'X'
tblXYZ
id name description category
so for making existing code work i may need to change above queries like that:
select * from tblXYZ a
inner join tblB b on a.id=b.Aid
where a.CategoryType='X'
but this isnt possible for me so what i can do?????
Solution:
instead of changing queries in SP what we can do we can create a new VIEW
with same name tblX and define it as :
select * from tblXYZ
where CategoryType='Y'
by using this VIEW we doesn't require to change SP's .
This is the best approach in fount till now ,, if there will anything new i'll let you know.
Happy Living.....
Happy Concepts.....
Happy Coding...........
No comments:
Post a Comment