I am not an expert in sql / sqlite.. suppose we have two tables:
CREATE TABLE child (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
);
CREATE TABLE MyTableB(
dog TEXT,
FOREIGN KEY(dogList) REFERENCES child(id)
);
how will the INSERT? is correct my createTable operations? I would like to have: a child can have more than one dog a dog can have more children
EDIT
What if I wanted all the children and for each child a list of dogs associated with that child?
Many-To-Many
In order to support a child having zero or more dogs and a dog belonging to zero or more children, your database table structure needs to support a Many-To-Many relationship. This requires three tables:
How to Insert
An insert into each of the three tables must be separate SQL statements, but can take place in the context of same transaction. Inserts into the child_dog table (known as the mapping table) must happen after inserts into the child and dog tables. This is for two related reasons:
Here are some example SQL statements for insert:
Inserting In Python
Although your question did not mention python, there is a python tag on this question so I'll assume you want to know how to do this in python. The sqlite3 module in python provides a nice little shortcut which saves you from having to run the 'last_insert_rowid()' function explicitly.
you need to have three tables for this. This is an example of
Many-to-Many
Relationship.