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?