I participate in a project and met a bad design by others,we have a table called task and each task has many users,the task table is as below:
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| id | varchar(40) | NO | PRI | NULL | |
| name | varchar(100) | YES | | NULL | |
| task_users | varchar(1000) | YES | | NULL | |
and the user is stored like aaa,bbb,ccc
in task_users
column,which means many user id are put into one column,I know this a very bad design but since it's an old project,I can not modify the table design.
Now I have a problem,if the user is deleted,how can I remove it from the task_users
column?
the user id is generated by UUID and it's at fixed length with 32 characters,so each user id is unique,such as 40cf5f01eb2f4d2c954412f27b3bf6eb
,but the problem is that the user id may appaer in any position of the task_users
column,so I do not know how to remove it
aaa,40cf5f01eb2f4d2c954412f27b3bf6eb,bbb -- in center
40cf5f01eb2f4d2c954412f27b3bf6eb,aaa,bbb -- in head
aaa,bbb,40cf5f01eb2f4d2c954412f27b3bf6eb -- in end
when remove the user id,the updated result is like
aaa,bbb
I want to know can we use one update sql to remove the specified user id and still keep the same data format?
Note:I am doing it in a MySQL stored procedure,additional variable may be helpful,but I still want to just use one sql to do it,the MySQL version is 5.0
Thanks in advance!