Jump to content

Relational Database structure question


jakeoh

Recommended Posts

Hi,

 

I want to design a little classified ads website for fun. Now I am thinking at how my DB should be structured. So far I have this (I omitted certain fields that are not relevant for my question):

 

Ad table

ad_id

ad_title

ad_description

ad_price

ad_startdate

ad_enddate

 

Categories table

cat_id

cat_name

cat_description

 

Ad-Categories table

ad_id

cat_id

 

User table

user_id

user_name

...

 

Ad-User table

ad_id

user_id

 

My questions are:

 

1. Does it seem like a good structure so far? It's my first time designing such a database, so I wouldn't know.

2. If a user posts an ad for the clothes category, he would have to select if the clothes are for men or women, and a specific size (say S, M, L, XL). Now where would that go in the database? In a new table? In the Ad table? In the Categories table?

3. What is the best datatype for the "Price" column? Is it decimal, or should I just use an integer and use php to deal with the decimals (for cents)?

 

Thanks in advance!

 

 

 

Link to comment
Share on other sites

1) Yes, that looks nice.  Nice and normalised to 3NF.

 

2) The only real way to adhere to good database design with this is to have separate tables for each category.  For example, clothes would have a table cat_clothes.  Exercise equipment would have cat_exercise. 

I know you probably don't want to go down this path, but there is too much variance between categories and what information needs to be stored.  Storing these in a single table would mean that you are storing a lot of redundant data.  Someone correct me here if you believe otherwise.

 

3) Use decimal(10,2) for fields that will contain monetary values. If you use a float it will round the values, while decimal won't.  I don't see how or why you would want to use an Integer data type here.  You need to store the amount accurately, you shouldn't have to manipulate/calculate prices.

Link to comment
Share on other sites

1) Thanks!

2) I have no problem doing that (one table per category) as one of my main goals is to practice designing databases... So using that solution, what tables would be required and which relation should be made? I guess I would create a Clothes table, that would relate to the Categories table through cat_id, and then in that table (Clothes) I would cover all possibilities (Women/Men/Unisex - different sizes)? But where is the specific information about, say, that specific Large sweater for Men is kept? In a new Category-Clothes table?

3) Great, thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.