Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Programming > Database Development
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-09-2008, 11:12 AM
Member
 
Join Date: Aug 2005
Posts: 88
Default Numerical ID's Several Tables or text ids in the same table?

Hi I have a dilemma with database table relationship that I am trying to solve.

My table is running quite slow on some queries I am using when i come to query the columns to build my menus.

I am trying to weigh up whether to

option 1. keep all data in one table, without using a primary key (my current table structure)

option 2. move the 2nd and 3rd column to another table and use primary key IDs to link them together (from reading around this seems to be the standard way)
  • Is there any proof that using ids in different tables is faster?, I will have to use more queries for this so i am worried it will slow things down
  • Are numerical ID's faster to query than text?
option 1:

I currently have a large amount of data in one table.

Structured like this:

product1|yes|2
product2|no|1
product3|yes|2

I am using this to build a sort of website, with menus that use the second and third column.

The 2nd menu would look like this.

Select you product:
-Yes
-No

And then on input of yes it would filter the table

PHP Code:
select products from table where product = 'yes'

option 2:

Is it faster to change the db tables to this structure

table1:
id|product
1|product1
2|product2
3|product3

table2:
1|yes|1
2|no|2
3|yes|3

table3:
1|2|1
2|1|2
3|2|3

Is this a better way to structure the data.

If I use this I will have to create an extra query each time before the query is executed in order to convert the text to an ID.

Basically my question is, is it quicker to use numerical ID's in table rather than using text?

Is there some special way to auto_increment all the tables automatically, as most of my data starts off in one table?
__________________
md
AskAGeek.com - Where geeks answer your computer and tech questions.
Ann-Lindsey.com - My Wife's Budget Fashion and Shopping Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-09-2008, 12:15 PM
BigAlReturns's Avatar
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 291
Send a message via MSN to BigAlReturns
Default

I think it's possibly a requirement of a primary key that it's numeric, but even if it's not then it will almost certainly be quicker, and also mean reduced index size.
I'm not aware of an automatic auto_increment, I would have the "main" table where the id is created by auto_increment, then use that key to insert into other tables.
As for table structure, have a search and read about database normalization. You should strive for the highest degree of normalization possible. Basically the idea is to use as few tables as possible, while making sure that no data is duplicated between tables. I'm not certain exactly what the function of the data in the tables is, i.e. what it means. Could you post a bit more code showing what you do with the data that is returned? Or just describe in a bit more detail exactly what the final menu should look like in different situations described by the database? If you can then I'll happily suggest a table structure for you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Thread Tools
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
text in Photoshop Nefrit Graphics and Multimedia 1 12-25-2007 08:42 AM
Hollow" text in Photoshop pntglobal Graphics and Multimedia 0 10-30-2007 03:23 AM


All times are GMT -5. The time now is 04:44 AM.


Website Design by Ducani Media Group
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.