SQLite – Should You Dynamically Add Rows to a Table or Use CSV in Objective C?

sqlite

Just like when adding a new contact in the ios contact app, you can add multiple phone numbers, and it doesn't know how many there will be, so therefore they don't know how many rows they should initially add in the table.
So how does that work, do they dynamically add rows to the table, or do they use csv?

Best Answer

They just properly normalize their database so that it is possible to store an arbitrary number of numbers; something like this:

CREATE TABLE Contacts (
    ContactID INTEGER PRIMARY KEY,
    Name TEXT
);
CREATE TABLE PhoneNumbers (
    ContactID INTEGER REFERENCES Contacts(ContactID),
    Number TEXT
);