SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


To-do list database design


To-do list database design

Author
Message
joseph.moffatt
joseph.moffatt
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 17
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
id name
1 John
2 Mike

list
id userid
1 1
2 1
3 2

listname
id name
1 Housekeeping
2 Banking

task
id name
1 Laundry
2 Washing up
3 Bake cookies
4 Clean bathroom
5 Water garden
6 Pay bills
7 Transfer funds
8 Apply for loan
9 Close account
10 Cancel credit card
11 Vacuum
12 Wash car
13 Tidy garage

listnametask
listid listnameid taskid
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
2 2 6
2 2 7
2 2 8
2 2 9
2 2 10
3 1 3
3 1 11
3 1 12
3 1 1
3 1 13
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63652 Visits: 17969
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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
joseph.moffatt
joseph.moffatt
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 17
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
listid listnameid
1 1
2 2
3 1

ListTask
listid taskid
1 1
1 2
1 3
1 4
1 5
2 6
2 7
2 8
2 9
2 10
3 3
3 11
3 12
3 1
3 13

Thanks for your advice/suggestions. :-) I don't have DDL yet as I wanted to get this right first.
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63652 Visits: 17969
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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search