CREATE VIEW UserParams (user_id, param, value)
AS SELECT id, "Address" , address
FROM New_User
UNION
SELECT id, "Phone", phone
FROM New_User
Mimic table in MySQL (view or stored function)
-
01-10-2022 - |
Question
Currently I have User structure which is defined in two tables: User (id, name) and UserParams (user_id, param, value) So, current data looks in a way below:
User:
id, name
1, "John"
2, "Bob"
UserParams:
user_id, param, value
1, "Address", "Kilmainham str"
1, "Phone", "+12345678"
I want to refactor database so User will have explicit columns address, phone and etc:
New User structure:
id, name, address, phone
1, "John", "Kilmainham str", "+12345678"
2, "Bob", "Orc's cave", "just speak up"
The bad thing, the database has many stored procedures which will be very difficult to refactor in a single streak. So, I want to have a view or stored function which will mimic old "UserParams" behavior.
SELECT * FROM UserParams WHERE user_id=1;
1, "Address", "Kilmainham str"
1, "Phone", "+12345678"
Is it any way to do that? Thanks.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow