Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe separated vs separate rows

Tags:

sql

mysql

I am using MySQL as the database for a Laravel application. Consider a table structure of following-

id brand_id numbers

Considering for against every brand_id there are around 5k numbers. I am unsure between the following approaches

  1. Store all 5k numbers in a single record pipe separated
  2. Store each of the 5k numbers as a separate record

Clueless as to which approach will result in a better performance

like image 255
Navin Nagpal Avatar asked Jan 15 '16 07:01

Navin Nagpal


1 Answers

Without knowing anything about Laravel, but something about databases my general answer would be that you should almost never store more that one item in a single record in a relational database - doing so breaks the relational model and makes the data very hard to work with, so the second approach is definitively better. Maybe you should read up on how relational databases function and about database normalization.

If you let a record hold more than one discrete item you can neither maintain relations between tables nor use indexing to increase performance, and you lose a lot of other important properties too.

like image 87
jpw Avatar answered Oct 22 '22 17:10

jpw