The reason SQL doesn't have arrays is because most people really don't need it. Relational databases (SQL is exactly what) work using relationships, and most of the time it’s best to assign one row of the table to each “bit of information”. For example, where you might think, “I need a list of things here,” create a new table instead, linking a row in one table to a row in another table. [1] Thus, you can represent the relationship M: N. Another advantage is that these links will not interfere with the line containing the associated element. And the database can index these rows. Arrays are usually not indexed.
If you do not need relational databases, you can use, for example, a repository of key values.
Read about database normalization , please. The golden rule: "[Each] non-key [attribute] must ensure the fact of the key, the entire key and nothing but the key." An array does too much. It has several facts and keeps order (which is not related to the relation itself). And performance is bad (see above).
Imagine that you have a table for people, and you have a table with the phone calls of people. Now you can make each line have a list of its phone calls. But many have many other relationships with many other things. Does this mean that my people table should contain an array for every single thing that it is connected to? No, this is not an attribute of the person himself.
[1]: This is normal if there are only two columns in the link table (primary keys from each table)! If the relationship itself has additional attributes, they should be presented in this table in columns.
Janus Troelsen Jun 28 '13 at 18:59 2013-06-28 18:59
source share