October 2, 2012 at 1:45 pm
Can anybody advise if the below design is good for a database of to-do lists where different users can submit lists of 5 items? Thanks 🙂
user
idname
1John
2Mike
list
iduserid
11
21
32
listname
idname
1Housekeeping
2Banking
task
idname
1Laundry
2Washing up
3Bake cookies
4Clean bathroom
5Water garden
6Pay bills
7Transfer funds
8Apply for loan
9Close account
10Cancel credit card
11Vacuum
12Wash car
13Tidy garage
listnametask
listidlistnameidtaskid
111
112
113
114
115
226
227
228
229
2210
313
3111
3112
311
3113
October 2, 2012 at 2:30 pm
It doesn't look too bad. I would highly recommend you NOT name your primary key ID in every table. You should give it a descriptive name. ListID for example. Otherwise you will be committing what I consider a major sin (A column name should remain consistent throughout the entire database). I am not sure what the TaskNameList table is for. The first 3 tables are a pretty straight forward parent/child/grandchild. The relationship is 1:* so there is no need for the the last table. What would help even more would be to have ddl along with constraints. Then we can get a better idea of what you are doing.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 2, 2012 at 3:52 pm
Thanks Sean, I've noted your point about primary key naming.
TaskNameList is a lookup table to associate lists, list names and tasks with each other. This is the part of the design I was unsure of. Take list id 3 for example: without TaskNameList, there is no way of knowing that it is has a name of Housekeeping and tasks of Baking cookies, Vacuum, Wash car, Laundry and Tidy garage unless foreign keys are added to the listname and task tables. But that means duplicating values in those columns, right?
My understanding was that lookup tables are are good practice. However, I've not seen a 3-column look-up table like TaskNameList. Perhaps it is better practice to replace TaskNameList with 2 2-column look-up tables:
ListName
listidlistnameid
11
22
31
ListTask
listidtaskid
11
12
13
14
15
26
27
28
29
210
33
311
312
31
313
Thanks for your advice/suggestions. 🙂 I don't have DDL yet as I wanted to get this right first.
October 2, 2012 at 7:01 pm
To me this seems like you don't need more than 2 tables. List and TaskList.
create table List
(
ListID int identity primary key,
UserID int not null,
ListName varchar(50) not null
)
create table TaskList
(
TaskListID int identity primary key,
ListID int not null,
TaskName varchar(50) not null,
SortOrder int not null
)
Then you just need to create the foreign key to your UserID and ListID.
From what you posted it looked like it was very possibly going to be over-normalized. For example making Task as a lookup table is probably a bit overkill. You might end up with a little duplication but that is probably not a big deal in this case.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply