Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: Need opinion on DB layout


Message #1 by Empier4552@a... on Wed, 3 Apr 2002 18:20:34 EST
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C1DB67.4BAF5220
Content-Type: text/plain

Think objects and properties.

You have an uploaded file object with some properties (file path, title,
description, date uploaded etc). That is split into categories. So you have
a category object with some properties (who created it, creation date, name
etc).

You table structure should look something like this:

FileUpload (table name)
UploadID	(PK)
FilePath
Title
DateAdded
CategoryID	(FK)

UploadCategory (table name)
CategoryID	(PK)
Name
DateAdded

notation explanation: PK means primary key ie it is your identity and is a
number automatically generated by the database. FK means foreign key and is
the value of the corresponding CategoryID.

This means 2 things: each time you add a category you don't need to add
another table, and it also means you are only storing the ID for the
category for each file which means space saving on the HD. Incidentally it
means you also have a properly normalised table structure <grin>.

With this structure you could return all the data in the two tables with:
SELECT *
FROM FileUpload
    JOIN UploadCategory ON
    UploadCategory.CategoryID = FileUpload.CategoryID

regards
David Cameron
nOw.b2b
dcameron@i...

>  -----Original Message-----
> From: 	Empier4552@a... [mailto:Empier4552@a...] 
> Sent:	Thursday, 4 April 2002 9:21 AM
> To:	professional php
> Subject:	[pro_php] Need opinion on DB layout
> 
> Heres the deal i have a DB and it will contain Upload descriptions etc.
There'll be different catagories. Should I have one table contain all this
info using Numerical IDs to differentiate the categories, or one table with
Text IDs (Catagory name) or different tables for each catagory? --- 


  Return to Index