Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

To-do list database design Expand / Collapse
Author
Message
Posted Tuesday, October 2, 2012 1:45 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 19, 2012 6:30 AM
Points: 6, 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
Post #1367268
Posted Tuesday, October 2, 2012 2:30 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:06 AM
Points: 13,300, Visits: 12,153
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 Moden's 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)
Post #1367286
Posted Tuesday, October 2, 2012 3:52 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 19, 2012 6:30 AM
Points: 6, 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.
Post #1367315
Posted Tuesday, October 2, 2012 7:01 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:06 AM
Points: 13,300, Visits: 12,153
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 Moden's 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)
Post #1367364
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse