1

task_set is a database with two colums(id, task):

 id    task 
  1     shout
  2     bark 
  3     walk
  4     run

assume there is another table with two colums(employee,task_order)

task_order is an ordered set of tasks, for example (2,4,3,1)

generally, the task_order is unchanged, but sometimes it may be inserted or deleted, e.g, (2,4,9,3,1) ,(2,4,1)

how to design such a database? I mean how to realize the ordered set?

1 Answer 1

1

If, and ONLY if you don't need to search inside the task_set column, or update one of it's values (i.e change 4,2,3 to 4,2,1), keeping that column as a delimited string might be an easy solution.

However, if you ever plan on searches or updates for specific values inside the task_set, then you better normalize that structure into a table that will hold employee id, task id, and task order.

Sign up to request clarification or add additional context in comments.

4 Comments

“normalize that structure into a table that will hold employee id, task id, and task order”? then how to order them?
order them by the task order column. tables are unsorted by nature, you must keep a column to use in select statements order by clause if you want to keep the order in the database.
the problem is how to order them in task order column? assigning numbers to them? let's say 1, 2,3,4. But now I want to insert an item between 1 and 2, so I have to make 2 as 3, 3 as 4 and 4 as 5?
I would use an exact numeric type for that, making your items 1.0, 2.0, 3.0 and 4.0. Then when you need to insert a row between existing rows 1.0 and 2.0 you can simply insert row 1.5...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.