If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Hello everybody, Design question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-06-09, 11:03
kalrudra kalrudra is offline
Registered User
 
Join Date: May 2009
Posts: 12
Hello everybody, Design question

Hi this is my first post in this forum, I have one query regarding database design.

I have 3 tables.

1) Upload(UploadId Primary key)
2) Category(CategoryId Primary Key)
3) Subcategory(SubcategoryId primary key)

relation among in them is...

Category (1) : (Many) Upload

Category(1) : (Many) Subcategory

My question is how should I design database and foreign key contraints?

I am eagerly waiting for your answers.

Thnx.
Reply With Quote
  #2 (permalink)  
Old 05-06-09, 11:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
you don't need separate category and subcategory tables

this might help: Categories and Subcategories
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-06-09, 12:05
kalrudra kalrudra is offline
Registered User
 
Join Date: May 2009
Posts: 12
Thank You r937,

I didn't know this technique before.

Much Appreciated.
Reply With Quote
  #4 (permalink)  
Old 05-06-09, 12:26
kalrudra kalrudra is offline
Registered User
 
Join Date: May 2009
Posts: 12
Can write like this?

Instead of adjacency model recommanded by r937,
can i write like following?

tblUpload
-----------------
UploadId(PK)
.................................................. .....................................

tblCategory
-----------
CategoryId(PK)
UploadId(FK)
.................................................. .....................................

tblSubCategory
---------------
SubcategoryId(PK)
CategoryId(FK)
UploadId(FK)
.................................................. .....................................
Reply With Quote
  #5 (permalink)  
Old 05-06-09, 13:39
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Why does UploadId appear in the Category table? It looks like you can determine the Category from the SubCategory table anyway. So I'd expect you can remove UploadId from Category. Of course, I don't know your data.
Reply With Quote
  #6 (permalink)  
Old 05-06-09, 16:48
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
The adjacency model lets you have subcategories of subcategories, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those, and subcategories of those (etc)

Yours allows only two layers deep. Is this what you require?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #7 (permalink)  
Old 05-06-09, 21:44
kalrudra kalrudra is offline
Registered User
 
Join Date: May 2009
Posts: 12
Quote:
Yours allows only two layers deep. Is this what you require?
Yes I want only 2 levels deep.
Reply With Quote
  #8 (permalink)  
Old 05-06-09, 21:56
kalrudra kalrudra is offline
Registered User
 
Join Date: May 2009
Posts: 12
Quote:
Why does UploadId appear in the Category table? It looks like you can determine the Category from the SubCategory table anyway. So I'd expect you can remove UploadId from Category. Of course, I don't know your data.
CORRECTED ONE:->

tblUpload
-----------------
UploadId(PK)
.................................................. .....................................

tblCategory
-----------
CategoryId(PK)
UploadId(FK)
.................................................. .....................................

tblSubCategory
---------------
SubcategoryId(PK)
CategoryId(FK)
.................................................. .....................................
Reply With Quote
  #9 (permalink)  
Old 05-07-09, 01:42
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
This doesn't look right either. If it is correct then each CategoryId can only have ONE upload, which appears to contradict what you said before: "Category (1) : (Many) Upload". My guess is that either CategoryId or SubCategoryId actually belongs in the Upload table and that UploadId should not go in the Category table.

Unfortunately these kinds of design-by-forum exercises tend to make very slow progress and are rarely much help in my experience. The best option may be to hire someone to assist you if you aren't familiar with how to model a database.
Reply With Quote
  #10 (permalink)  
Old 05-07-09, 02:59
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Modelling a substantial business problem, yes. Something like this - nah. This and other forums have helped sort out thousands and thousands of problems of this sort. If they aren't of any use then why do you continue to contribute?

Kalundra - the principle problem is you have not explained in detail what you are trying to achieve, what you are modelling, what are the real world circumstances. You keep posting models, but we don't know if they are appropriate or not unless you tell us the background.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #11 (permalink)  
Old 05-07-09, 12:00
kalrudra kalrudra is offline
Registered User
 
Join Date: May 2009
Posts: 12
Quote:
Kalundra - the principle problem is you have not explained in detail what you are trying to achieve, what you are modelling, what are the real world circumstances. You keep posting models, but we don't know if they are appropriate or not unless you tell us the background.
I am developing community based website where people can contribute their images, documents, audios and videos.
client's requirement specification tells that all of those uploads have categories and subcategories.(no subsubcategories). After thinking lots of alternate solutions I have come across following design..

Upload belong to particular category or subcategory. Categories have subcategories or they don't have any subcategory. In that case it may be NULL.

Category
------------
CategoryId(PK)
CategoryName

Subcategory
------------
SubcategoryId(PK)
CategoryId(FK) ref Category(CategoryId)
SubcategoryName

Upload
-------------
UploadId(PK)
CategoryId(FK) ref Category (CategoryId)
SubcategoryId(FK) ref Subcategory (SubcategoryId)
UploadName
....

really want to know your point of view..
===========================================

Last edited by kalrudra; 05-07-09 at 12:06.
Reply With Quote
  #12 (permalink)  
Old 05-07-09, 13:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by kalrudra
really want to know your point of view..
Category
------------
CategoryId(PK)
CategoryName
ParentCat(FK) references Category (CategoryId)

Upload
-------------
UploadId(PK)
UploadName
CategoryId(FK) references Category (CategoryId)


K.I.S.S.
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On