Jump to content


Photo

table with multiple columns or several tables with redundant data?


  • Please log in to reply
12 replies to this topic

#1 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 21 January 2013 - 03:42 PM

the question is a little different from the title though, as i provide the constraints.

If i insert a particular value in say, 8 tables, just once, and access other fields of that table many times, is it faster than having a big table with like, 20 columns, and accessing multiple fields, provided i would be using queries like " select * from table" and other time consuming queries like count of all entries in the table??

#2 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 21 January 2013 - 05:56 PM

1. You shouldn't be using select *, specify just the columns you need. Retrieving redundant data is inefficient.

2. Count all entries in a table is not time consuming as no records have to be read, mysql knows how many. (ie SELECT COUNT(*) FROM tablename).

Apart from those observations I haven't clue what you mean.

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#3 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 22 January 2013 - 04:48 AM

I'll explain what am i doing.
I have a website, on php and mysql.

1st approach

A person registers, his username is stored in 8 different tables, which contain different info about him.
Referencing data becomes easier, but is very time consuming ( but, only once).

2nd approach

A person registers, his username is stored only once, but that table has many columns, say about 20.
Table becomes large.

which one is better?

I can select only the required values as you pointed out, but i would have to use "select * from table" at some places.

Edited by sid0972, 22 January 2013 - 04:53 AM.


#4 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 22 January 2013 - 05:09 AM

20 is not large

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#5 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 22 January 2013 - 10:51 AM

thank you

#6 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 22 January 2013 - 11:43 AM

On the other hand, ensure your data is correctly normalized

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#7 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 24 January 2013 - 02:39 PM

i have read about normalization , and, in a nutshell, it means that using the best possible queries to to the required job without having retrieve irrelevant data, right??

not talking about 3NF or 5NF or BCNF, they are way over my head.

#8 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 24 January 2013 - 07:17 PM

i have read about normalization , and, in a nutshell, it means that using the best possible queries to to the required job without having retrieve irrelevant data, right??


Wrong!.

It's about not storing redundant data, organizing your data and designing your tables so you can use the best possible queries to do the required job.

What is the proposed structure of your 8 tables and the alternative single 20-column table?

Edited by Barand, 24 January 2013 - 07:25 PM.

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#9 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 25 January 2013 - 12:27 PM

its like this,

table 1 table 2
username username
info 1 info 3
info 2 info 4

and another 6 tables

main table
username
info 5
.
.
.
info 15


the fields info1-info 4 will be stored repeatedly for a single user, whereas in main table they are stored only once for a single user.

#10 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 25 January 2013 - 03:32 PM

The repeated data should certainly be in separate tables so avoid the all-in-one table solution.

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#11 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 26 January 2013 - 12:48 PM

so what am i doing is not the worst approach??

#12 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,365 posts
  • LocationCheshire, UK

Posted 26 January 2013 - 01:18 PM

When all I have seen is Info1 .... InfoN as data items there is no way I could give a verdict either way with any degree of certainty. As I've said, normalize your data and all will be well.

http://forums.phpfre...s/#entry1408360

Edited by Barand, 26 January 2013 - 01:38 PM.

moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#13 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 26 January 2013 - 02:51 PM

thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com